package com.yunzo.coc.api;

import com.jfinal.aop.Before;
import com.jfinal.aop.ClearInterceptor;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.upload.UploadFile;
import com.yunzo.coc.common.Require;
import com.yunzo.coc.common.bean.BaseResponse;
import com.yunzo.coc.common.bean.Code;
import com.yunzo.coc.common.bean.DataResponse;
import com.yunzo.coc.common.bean.DatumResponse;
import com.yunzo.coc.common.bean.coc.CotactsData;
import com.yunzo.coc.common.bean.coc.CotactsNode;
import com.yunzo.coc.common.bean.coc.GroupBusessAction;
import com.yunzo.coc.common.bean.coc.GroupContactEntey;
import com.yunzo.coc.common.bean.coc.GroupDynamicinfoEntey;
import com.yunzo.coc.common.bean.coc.GroupEcInfoEntey;
import com.yunzo.coc.common.bean.coc.GroupEcInfoListEntey;
import com.yunzo.coc.common.bean.coc.GroupEcInfoListObjectEntey;
import com.yunzo.coc.common.bean.coc.GroupInfoEntey;
import com.yunzo.coc.common.bean.coc.GroupInforminfoEntey;
import com.yunzo.coc.common.bean.coc.GroupIsOpenContactEntey;
import com.yunzo.coc.common.bean.coc.GroupMemberCompanyEntey;
import com.yunzo.coc.common.bean.coc.GroupMemberInfoEntey;
import com.yunzo.coc.common.bean.coc.GroupMemberSysSmsEntey;
import com.yunzo.coc.common.bean.coc.MemberBusinessListEntey;
import com.yunzo.coc.common.bean.coc.MemberBusinessinfoEntey;
import com.yunzo.coc.common.bean.coc.MemberBusinessinfoTopFiveEntey;
import com.yunzo.coc.common.bean.coc.MemberCAddressEntey;
import com.yunzo.coc.common.bean.coc.MemberShowtimeEntey;
import com.yunzo.coc.common.bean.coc.MemeberBuinessinfoCommentEntey;
import com.yunzo.coc.common.bean.coc.ShowmeinfoEntey;
import com.yunzo.coc.common.bean.coc.SystemCollectEntey;
import com.yunzo.coc.common.bean.coc.SystemTradeEntey;
import com.yunzo.coc.common.bean.coc.YunzoCityEntey;
import com.yunzo.coc.common.bean.coc.YunzoInfoEntey;
import com.yunzo.coc.common.bean.coc.YunzoTopFiveInfoEntey;
import com.yunzo.coc.common.bean.param.Feedback;
import com.yunzo.coc.common.bean.param.GroupBusessInfo;
import com.yunzo.coc.common.bean.param.GroupEcOrder;
import com.yunzo.coc.common.bean.param.GroupInfoEntny;
import com.yunzo.coc.common.bean.param.GroupJoinusEntry;
import com.yunzo.coc.common.bean.param.MemberReplyInbox;
import com.yunzo.coc.common.bean.param.SeachValue;
import com.yunzo.coc.common.bean.param.Showme;
import com.yunzo.coc.common.bean.param.Trade;
import com.yunzo.coc.interceptor.TokenInterceptor;
import com.yunzo.coc.model.BasicDictModel;
import com.yunzo.coc.model.BasicTradeModel;
import com.yunzo.coc.model.GroupBusinessinfoBrowseModel;
import com.yunzo.coc.model.GroupBusinessinfoModel;
import com.yunzo.coc.model.GroupContactsModel;
import com.yunzo.coc.model.GroupDynamicinfoModel;
import com.yunzo.coc.model.GroupEcprodOrderModel;
import com.yunzo.coc.model.GroupEcprodinfoModel;
import com.yunzo.coc.model.GroupEcprodtypeinfoModel;
import com.yunzo.coc.model.GroupInfoModel;
import com.yunzo.coc.model.GroupInformBrowse;
import com.yunzo.coc.model.GroupInformJoinModel;
import com.yunzo.coc.model.GroupInforminfoModel;
import com.yunzo.coc.model.GroupJoinusentryModel;
import com.yunzo.coc.model.GroupMShowBrowseModel;
import com.yunzo.coc.model.GroupMemberCaddressModel;
import com.yunzo.coc.model.GroupMemberCompanyModel;
import com.yunzo.coc.model.GroupMemberConcernModel;
import com.yunzo.coc.model.GroupMemberLabelModel;
import com.yunzo.coc.model.GroupMemberModel;
import com.yunzo.coc.model.GroupMemberShowtimeModel;
import com.yunzo.coc.model.GroupMemberinfoModel;
import com.yunzo.coc.model.SystemCollectModel;
import com.yunzo.coc.model.SystemJpushUrlInfoModel;
import com.yunzo.coc.model.SystemJpushUserReadInfoModel;
import com.yunzo.coc.model.SystemPointlikeModel;
import com.yunzo.coc.model.SystemReviewModel;
import com.yunzo.coc.model.SystemReviewReplyModel;

import java.io.File;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.httpclient.util.DateUtil;

import com.yunzo.coc.common.utils.CotactsNodeUtil;
import com.yunzo.coc.common.utils.DateUtils;
import com.yunzo.coc.common.utils.FileUtils;
import com.yunzo.coc.common.utils.IMGSize;
import com.yunzo.coc.common.utils.JsonObjectUtil;
import com.yunzo.coc.common.utils.OrderUtils;
import com.yunzo.coc.common.utils.PushUtils;
import com.yunzo.coc.common.utils.StringUtils;

/**
 * 团体信息 接口 http://localhost:8080/cocapi/api/group/getgroupinfobymid?groupid=
 * 88888888888888888888888888888888&token=6b0698207195413887de0435dac0b125MHctiE
 * http://localhost:8080/cocapi/api/group/getgroupcontactlist?groupid=
 * 88888888888888888888888888888888
 * &pagesize=5&token=198eed0fd4a64a13b20c4cfd5a8ac206MaavzH
 * 
 * 获取团体信息 POST /api/group/getgroupinfobymid 申请加入团体 POST
 * /api/group/applyforjoingroup 获取团体动态集合 POST /api/group/getgroupdynamicinfolist
 * 获取团体通知集合 POST /api/group/getgroupinforminfolist 团体通知操作 POST
 * /api/group/joingroupinforminfo 检查团体通讯录是否有更新 POST
 * /api/group/checkgroupcontactsupdate 获取团体通讯录集合 POST
 * /api/group/getgroupcontactlist 获取会员公司集合 POST /api/group/getmembercompanylist
 * 根据关键字搜索团体通讯录个人信息 POST /api/group/getmembercompanylist 获取会员发页的商机列表 POST
 * /api/group/getmemberbusinessinfolist 根据关键字搜索会员常用通讯录列表 POST
 * /api/group/querycollectlist 获取团体商机列表 POST /api/group/getgroupbusinessinfolist
 * 获取团体商机详细信息 POST /api/group/getgroupbusinessinfobybid
 * 
 * @author xiaobo
 */
public class GroupAPIController extends BaseAPIController {

	/**
	 * 获取团体信息 POST /api/group/getgroupinfobymid
	 */
	public void getgroupinfobymid() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		// 根据团体ID查询
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		if (!notNull(Require.me().put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		GroupInfoModel GM = GroupInfoModel.dao.findById(groupid);
		DatumResponse response = new DatumResponse();
		GroupInfoEntey ginfo = new GroupInfoEntey();
		if (GM == null) {
			response.setCode(Code.FAIL).setMessage("group is not found");
		} else {
			ginfo.setN0(GM.getStr(GroupInfoModel.GROUPLOGO));
			ginfo.setN1(GM.getStr(GroupInfoModel.GNAME));
			ginfo.setN2(GM.getStr(GroupInfoModel.GINTRO));
			ginfo.setN3(GM.getStr(GroupInfoModel.GCTELLPHONE));
			ginfo.setN4(GM.getStr(GroupInfoModel.GADDRESS));
			ginfo.setN5(GM.getStr(GroupInfoModel.GCEMAIL));
			ginfo.setN6(GM.getStr(GroupInfoModel.GURL));
			ginfo.setN7(GM.getStr(GroupInfoModel.APPQCODE));
			ginfo.setN8(GM.getStr(GroupInfoModel.APPTURL));
			response.setDatum(ginfo);
			response.setMessage("success");
		}

		renderJson(response);
	}

	/**
	 * 申请加入团体 POST /api/group/applyforjoingroup
	 */
	public void applyforjoingroup() {
		BaseResponse response = new BaseResponse();
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		GroupJoinusEntry fb = null;
		String groupid=null, mid=null,did=null,realname=null,tel=null,comname=null,comduty=null,comadd=null,joingroupid=null,joincomment=null;// 申请人信息
	
		try {
			fb = getRepuestJosnObject(getRequest().getReader(), GroupJoinusEntry.class);// 取出请求接口参数
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (fb != null) {
			groupid=fb.getGroupid();
			mid=fb.getMid();
			did=fb.getDid();
			realname=fb.getMname();
			tel = fb.getTellphone();
			comname=fb.getCompanyname();
			comduty=fb.getCompanyduty();
			comadd = fb.getComaddress();
			joincomment= fb.getJoinjustly();
			joingroupid=fb.getJoingroupid();
		}else
		{
			return;
		}
		// 校验参数, 确保不能为空
		if (!notNull(Require.me()
				.put(did, "did can not be null")
				.put(groupid, "groupid can not be null"))){
			return;
		}
		boolean flag = new GroupJoinusentryModel()
				.set(GroupJoinusentryModel.ID, getCreateUUId())
				.set(GroupJoinusentryModel.VERSION, 0)
				.set(GroupJoinusentryModel.REALNAME, realname)
				.set(GroupJoinusentryModel.MID, tel)
				.set(GroupJoinusentryModel.COMPAYNNAME, comname)
				.set(GroupJoinusentryModel.COMPANYDUTY, comduty)
				.set(GroupJoinusentryModel.COMADDRESS, comadd)
				.set(GroupJoinusentryModel.GROUPID, joingroupid)
				.set(GroupJoinusentryModel.JOINJUESTLY, joincomment)
				.set(GroupJoinusentryModel.JOINDATETIME, DateUtils.getDate())
				.save();

		renderJson(response.setCode(flag ? Code.SUCCESS : Code.FAIL)
				.setMessage(
						flag ? Code.FINAL_STRING_SUCCESS
								: Code.FINAL_STRING_ERROR));
	}

	/**
	 * 获取团体动态集合 POST /api/group/getgroupdynamicinfolist
	 */
	public void getgroupdynamicinfolist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int size = getParaToInt("pagesize", 0);// 分页大小

		// 校验参数, 确保不能为空
		if (!notNull(Require.me()
				.put(did, "did can not be null")
				.put(groupid, "groupid can not be null")
				.put(size, "pagesize can not be null"))) {
			return;
		}
		List<GroupDynamicinfoModel> gdylist = GroupDynamicinfoModel.dao.find(
				GROUPDYNAMICINFOLISTSQL, groupid, size);

		List<GroupDynamicinfoEntey> gdelist = new ArrayList<GroupDynamicinfoEntey>();
		if (gdylist != null) {
			GroupDynamicinfoEntey gde = null;
			for (GroupDynamicinfoModel gdyn : gdylist) {
				gde = new GroupDynamicinfoEntey();
				gde.setN0(gdyn.getStr(GroupDynamicinfoModel.ID));
				gde.setN1(gdyn.getStr(GroupDynamicinfoModel.DYLOGO));
				gde.setN2(gdyn.getStr(GroupDynamicinfoModel.DYTITLE));
				gde.setN3(gdyn.getStr(GroupDynamicinfoModel.DYCOMMENT));
				gde.setN4(DateUtils.format(gdyn.getDate(GroupDynamicinfoModel.CREATETIME), "yyyy-MM-dd"));
				gde.setN5(0);
				gde.setN6(0);
				gde.setN7(0);

				gdelist.add(gde);
			}
		}
		List<SystemJpushUrlInfoModel> listsjuim=SystemJpushUrlInfoModel.dao.find("select * from y_system_jpush_urlinfo where 1=1 and  groupid=? and type=?", groupid,1);
		if(listsjuim!=null)
		{
			for(SystemJpushUrlInfoModel sjum:listsjuim)
			{
				new SystemJpushUserReadInfoModel().set(SystemJpushUserReadInfoModel.ID, getCreateUUId())
				.set(SystemJpushUserReadInfoModel.MIDS, mid)
				.set(SystemJpushUserReadInfoModel.PUSHIDS, sjum.getStr(SystemJpushUrlInfoModel.ID)).set(SystemJpushUserReadInfoModel.CREATETIME, DateUtils.getDate()).save();
			}
		}
		DataResponse response = new DataResponse();
		response.setCode(gdylist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gdylist != null ? "SUCCESS" : "没有动态信息");

		response.setData(gdelist);
		renderJson(response);

	}

	/**
	 * 获取团体动态详情 POST /api/group/getgroupdynamicinfoObject
	 */
	public void getgroupdynamicinfoObject() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String did = getPara("did");// 类型ID
		String mid = getPara("mid");// 会员手机号码
		String groupid = getPara("groupid");// 团体ID
		String dynid = getPara("dynid");// 动态ID
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(did, "did can not be null")
				.put(groupid, "groupid can not be null")
				.put(dynid, "dynid can not be null"))) {
			return;
		}
		GroupDynamicinfoModel gdyn = GroupDynamicinfoModel.dao.findById(dynid);
		GroupDynamicinfoEntey gde = null;
		if (gdyn != null) {
			SystemPointlikeModel spm = null;
			SystemReviewModel srm = null;

			gde = new GroupDynamicinfoEntey();
			gde.setN0(gdyn.getStr(GroupDynamicinfoModel.ID));
			gde.setN1(gdyn.getStr(GroupDynamicinfoModel.DYLOGO));
			gde.setN2(gdyn.getStr(GroupDynamicinfoModel.DYTITLE));
			gde.setN3(gdyn.getStr(GroupDynamicinfoModel.DYCOMMENT));
			gde.setN4(DateUtils.formatDate(gdyn
					.getDate(GroupDynamicinfoModel.CREATETIME)));
			// 统计条数
			srm = SystemReviewModel.dao.findFirst(GET_REVIEW_SUMNUMBER_SQL,
					groupid, did, dynid);
			gde.setN5(srm != null ? srm.getNumber(SystemReviewModel.SCOUNT)
					.intValue() : 0);
			spm = SystemPointlikeModel.dao.findFirst(
					GET_POINTLIKE_SUMNUMBER_SQL, groupid, did, dynid);
			gde.setN6(spm != null ? spm.getNumber(SystemPointlikeModel.SCOUNT)
					.intValue() : 0);
			spm = SystemPointlikeModel.dao.findFirst(GET_POINTLIKE_ISOPEN_SQL,
					groupid, did, dynid, mid);
			gde.setN7(spm != null ? 0 : 1);

		}

		DatumResponse response = new DatumResponse();
		response.setCode(gdyn != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gdyn != null ? "SUCCESS" : "没有动态详情");

		response.setDatum(gde);
		renderJson(response);
	}

	/**
	 * 获取团体通知集合 POST /api/group/getgroupinforminfolist
	 */
	public void getgroupinforminfolist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String mid = getPara("mid");// 手机号码
		String groupid = getPara("groupid");// 团体ID
		String did = getPara("did");// 类型ID
		int size = getParaToInt("pagesize", 0);// 分页大小

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null")
				.put(size, "pagesize can not be null"))) {
			return;
		}

		List<GroupInforminfoModel> gdylist = GroupInforminfoModel.dao.find(
				GROUPINFORMINFOLISTSQL, groupid, size);
		List<GroupInforminfoEntey> gdelist = new ArrayList<GroupInforminfoEntey>();
		if (gdylist != null) {
			GroupInforminfoEntey gde = null;
			SystemReviewModel srm = null;
			GroupInformBrowse gib = null;
			for (GroupInforminfoModel gdyn : gdylist) {
				gde = new GroupInforminfoEntey();
				gde.setN0(gdyn.getStr(GroupInforminfoModel.ID));
				gde.setN1(gdyn.getStr(GroupInforminfoModel.INFOLOGO));
				gde.setN2(gdyn.getStr(GroupInforminfoModel.INFOTITLE));
				gde.setN3(gdyn.getStr(GroupInforminfoModel.INFOCOMMENT));
				gde.setN4(DateUtils.format(gdyn
						.getDate(GroupInforminfoModel.CREATETIME), "yyyy-MM-dd"));
				// gde.setN4(gdyn.getStr(DateUtils.formatDate(gdyn.getDate(GroupInforminfoModel.INFOBEGINTIME))+"-"+DateUtils.formatDate(gdyn.getDate(GroupInforminfoModel.INFOENDTIME))));
				// 统计条数
				srm = SystemReviewModel.dao.findFirst(GET_REVIEW_SUMNUMBER_SQL,
						groupid, did, gdyn.getStr(GroupInforminfoModel.ID));
				gde.setN5(srm != null ? srm.getNumber(SystemReviewModel.SCOUNT)
						.intValue() : 0);
				gib=GroupInformBrowse.dao.findFirst(GROUPINFOFORMBROWSE_SUMNUMBER_SQL, gdyn.getStr(GroupInforminfoModel.ID));
				
				gde.setN6(gib != null ? gib.getNumber(GroupInformBrowse.SCOUNT).intValue() : 0);
				gde.setN7(0);
				gde.setN8(0);
				gdelist.add(gde);
			}
		}
		List<SystemJpushUrlInfoModel> listsjuim=SystemJpushUrlInfoModel.dao.find("select * from y_system_jpush_urlinfo where 1=1 and  groupid=? and type=?", groupid,2);
		if(listsjuim!=null)
		{
			for(SystemJpushUrlInfoModel sjum:listsjuim)
			{
				new SystemJpushUserReadInfoModel().set(SystemJpushUserReadInfoModel.ID, getCreateUUId())
				.set(SystemJpushUserReadInfoModel.MIDS, mid)
				.set(SystemJpushUserReadInfoModel.PUSHIDS, sjum.getStr(SystemJpushUrlInfoModel.ID)).set(SystemJpushUserReadInfoModel.CREATETIME, DateUtils.getDate()).save();
			}
		}
		DataResponse response = new DataResponse();
		response.setCode(gdylist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gdylist != null ? "SUCCESS" : "团体没有通知信息");

		response.setData(gdelist);
		renderJson(response);
	}

	/**
	 * 获取团体通知详情 POST /api/group/getgroupinforminfoObject
	 */
	public void getgroupinforminfoObject() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String infoid = getPara("infoid");// 手机号码
		String mid = getPara("mid");// 手机号码
		String groupid = getPara("groupid");// 团体ID
		String did = getPara("did");// 类型ID
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(infoid, "infoid can not be null")
				.put(did, "did can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null"))) {
			return;
		}
		GroupInforminfoModel gdyn = GroupInforminfoModel.dao.findById(infoid);
		GroupInforminfoEntey gde = null;
		if (gdyn != null) {
			SystemPointlikeModel spm = null;
			GroupInformJoinModel gijm = null;

			gde = new GroupInforminfoEntey();
			gde.setN0(gdyn.getStr(GroupInforminfoModel.ID));
			gde.setN1(gdyn.getStr(GroupInforminfoModel.INFOLOGO));
			gde.setN2(gdyn.getStr(GroupInforminfoModel.INFOTITLE));
			gde.setN3(gdyn.getStr(GroupInforminfoModel.INFOCOMMENT));
			gde.setN4(DateUtils.format(gdyn
					.getDate(GroupInforminfoModel.INFOBEGINTIME),"yyyy年MM月dd日HH")+ "时,"+ DateUtils.format(gdyn.getDate(GroupInforminfoModel.INFOENDTIME),"yyyy年MM月dd日HH")+"时");
			gijm = GroupInformJoinModel.dao.findFirst(
					GROUPINFORMINFO_SUMNUMBER_SQL, groupid, infoid);
			gde.setN5(gijm != null ? gijm
					.getNumber(GroupInformJoinModel.SCOUNT).intValue() : 0);
			spm = SystemPointlikeModel.dao.findFirst(
					GET_POINTLIKE_SUMNUMBER_SQL, groupid, did, infoid);
			gde.setN6(spm != null ? spm.getNumber(SystemPointlikeModel.SCOUNT)
					.intValue() : 0);
			spm = SystemPointlikeModel.dao.findFirst(GET_POINTLIKE_ISOPEN_SQL,
					groupid, did, infoid, mid);
			gde.setN7(spm != null ? 0 : 1);
			gijm = GroupInformJoinModel.dao.findFirst(
					GROUPINFORMINFO_ISJOIN_SQL, groupid, infoid, mid);
			gde.setN8(gijm != null ? 0 : 1);
			List<GroupInformBrowse> browselist = GroupInformBrowse.dao
					.find(GINFOMEMBERBIBROWSE_ALL_SQL, infoid);
			List<SystemCollectEntey> browseobecjtlist = null;
			// GroupMemberinfoModel userinfo=null;
			 GroupMemberModel nowUser = null;//定义会员基础
			if (browselist != null) {
				browseobecjtlist = new ArrayList<SystemCollectEntey>();
				SystemCollectEntey sce = null;
				for (GroupInformBrowse gbb : browselist) {
					sce = new SystemCollectEntey();
					sce.setN0(gbb.getStr(GroupInformBrowse.MID));
					//userinfo=GroupMemberinfoModel.dao.findFirst(MEMBERINFOMIDSSQL,
							//gbb.getStr(GroupInformBrowse.MID));
					//通过mid查询会员基础数据
					nowUser = GroupMemberModel.dao.findFirst(MEMBERMIDSSQL,
							gbb.getStr(GroupInformBrowse.MID));
					if(nowUser!=null){
//						sce.setN1(userinfo.getStr(GroupMemberinfoModel.HEADIMAGE));
						sce.setN1(nowUser.getStr(GroupMemberModel.HEADIMAGE));
						browseobecjtlist.add(sce);
					}
				}
			}
			gde.setN9(browseobecjtlist);
		}
		// 记录用户打开通知详情
		new GroupInformBrowse()
				.set(GroupInformBrowse.ID, getCreateUUId())
				.set(GroupInformBrowse.VERSION, 0)
				.set(GroupInformBrowse.ORDERIDS, 0)
				.set(GroupInformBrowse.MID, mid)
				.set(GroupInformBrowse.GINFOIDS, infoid)
				.set(GroupInformBrowse.CREATETIME,
						DateUtils.getDate()).save();
		
		DatumResponse response = new DatumResponse();
		response.setCode(gdyn != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gdyn != null ? "SUCCESS" : "没有通知详情");
		response.setDatum(gde);
		renderJson(response);
	}

	/**
	 * 团体通知操作 POST /api/group/joingroupinforminfo
	 */
	public void joingroupinforminfo() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String infoid = getPara("infoid");// 团体通知ID
		int type = getParaToInt("type", 0);// 操作类型

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(infoid, "infoid can not be null")
				.put(groupid, "groupid can not be null")
				.put(type, "type can not be null"))) {
			return;
		}
		boolean flag = false;
		if (type == 0) {
			flag = new GroupInformJoinModel()
					.set(GroupInformJoinModel.ID, getCreateUUId())
					.set(GroupInformJoinModel.VERSION, 0)
					.set(GroupInformJoinModel.ORDERIDS, 0)
					.set(GroupInformJoinModel.GROUPIDS, groupid)
					.set(GroupInformJoinModel.INFOIDS, infoid)
					.set(GroupInformJoinModel.MIDS, mid)
					.set(GroupInformJoinModel.CREATETIME, DateUtils.getDate())
					.save();
		} else {
			if (Db.update(DEL_GROUPINFORMINFO_SQL, groupid, infoid, mid) != 0)
				flag = true;
		}
		GroupInformJoinModel gijm = GroupInformJoinModel.dao.findFirst(
				GROUPINFORMINFO_SUMNUMBER_SQL, groupid, infoid);
		// 返回数据
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL, flag ? ""
				+ (gijm != null ? gijm.getNumber(GroupInformJoinModel.SCOUNT)
						.intValue() : 0) : Code.FINAL_STRING_ERROR));
	}

	/**
	 * 检查团体信息是否有更新 POST /api/group/getgroupinfoisupdate
	 */
	public void getgroupinfoisupdate() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int localContactCacheVersion = getParaToInt("localContactCacheVersion",
				0);// 操作类型

		// 校验参数, 确保不能为空
		if (!notNull(Require
				.me()
				.put(groupid, "groupid can not be null")
				.put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(localContactCacheVersion,
						"localContactCacheVersion can not be null"))) {
			return;
		}
		GroupInfoModel gm = GroupInfoModel.dao.findFirst(
				GROUPINFO_MAX_VERSION_SQL, groupid);
		// 返回数据
		renderJson(new BaseResponse(
				Code.SUCCESS,
				localContactCacheVersion == gm.getNumber(
						GroupContactsModel.VERSION).intValue() ? Code.FINAL_STRING_EORR
						: Code.FINAL_STRING_SUSS));
	}

	/**
	 * 检查团体通讯录是否有更新 POST /api/group/checkgroupcontactsupdate
	 */
	public void checkgroupcontactsupdate() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int localContactCacheVersion = getParaToInt("localContactCacheVersion",
				0);// 操作类型

		// 校验参数, 确保不能为空
		if (!notNull(Require
				.me()
				.put(groupid, "groupid can not be null")
				.put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(localContactCacheVersion,
						"localContactCacheVersion can not be null"))) {
			return;
		}

		GroupContactsModel GCM = GroupContactsModel.dao.findFirst(
				GROUPCONTACTS_MAX_VERSION_SQL, groupid);
		// 返回数据
		renderJson(new BaseResponse(
				Code.SUCCESS,
				localContactCacheVersion == GCM.getNumber(
						GroupContactsModel.VERSION).intValue() ? Code.FINAL_STRING_EORR
						: Code.FINAL_STRING_SUSS));
	}

	/**
	 * 获取团体通讯录集合 POST /api/group/getgroupcontactlist
	 */
	public void getgroupcontactlist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
	
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(groupid, "groupid can not be null")
				.put(mid, "mid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		List<GroupContactsModel> gcontactlist = GroupContactsModel.dao.find(GROUPCONTACTS_INFOLIST_SQL, groupid);
		List<GroupContactEntey> grcontactlist = null;
		GroupContactEntey gcontact = null;
		if(gcontactlist!=null&&gcontactlist.size()>0)
		{
			grcontactlist=new ArrayList<GroupContactEntey>();
			for(GroupContactsModel gcm:gcontactlist)
			{
				gcontact = new GroupContactEntey();
				gcontact.setN0(gcm.getStr(GroupContactsModel.CNAMES));
				gcontact.setN1(gcm.getStr(GroupContactsModel.PARENTNAME));
				gcontact.setN3(gcm.getNumber(GroupContactsModel.VERSION)
						.intValue());
				gcontact.setN4(gcm.getNumber(GroupContactsModel.ORDERIDS)
						.intValue());
				gcontact.setN6(gcm.getStr(GroupContactsModel.ID));
				
				if(gcm.getStr(GroupContactsModel.MIDS)!=null)
				{
					if(gcm.getStr(GroupContactsModel.MIDS).indexOf(",")!=-1)
					{
						gcontact.setN2(gcm.getStr(GroupContactsModel.MIDS).split(",").length);
					}else if(gcm.getStr(GroupContactsModel.MIDS).length()==11)
					{
						gcontact.setN2(1);
					}else
						gcontact.setN2(0);
				}else
				{
					gcontact.setN2(0);
				}
				
				gcontact.setN5(null);
				grcontactlist.add(gcontact);
			}
		}

		DataResponse response = new DataResponse();
		response.setCode(gcontactlist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gcontactlist != null ? "SUCCESS" : "团体没有通讯录信息");

		response.setData(grcontactlist);
		renderJson(response);

	}
	/**
	 * 获取团体通讯录集合 POST /api/group/getgroupcontactlisttreedata 层级关系树结构
	 */
	public void getgroupcontactlisttreedata() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
	
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(groupid, "groupid can not be null")
				.put(mid, "mid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		//查询父级职位
		List<GroupContactsModel> gcontactlist = GroupContactsModel.dao.find(GROUPCONTACTS_PART_INFOLIST_SQL, groupid);
		List<GroupContactsModel> gcontactlistchild=GroupContactsModel.dao.find(GROUPCONTACTS_ALLCHILD_INFOLIST_SQL, groupid);
		CotactsNodeUtil util=null;
		List<CotactsData> contdata=null;
		CotactsData csdata=null;
		if(gcontactlist!=null&&gcontactlist.size()>0)
		{
			contdata=new ArrayList<CotactsData>();
			for(GroupContactsModel gcm:gcontactlist)
			{
				csdata=new CotactsData();
				util=new CotactsNodeUtil();
				csdata.setN0(gcm.getStr(GroupContactsModel.CNAMES));
				if(gcontactlistchild!=null&&gcontactlistchild.size()>0)
					csdata.setN1(util.getChildCotactsNodes(gcontactlistchild, gcm.getStr(GroupContactsModel.ID)));
				else
					csdata.setN1(null);
				csdata.setN2(gcm.getStr(GroupContactsModel.ID));
				csdata.setSnum(getContactsSnum(gcm.getStr(GroupContactsModel.MIDS)));
				contdata.add(csdata);
			}
		}

		DataResponse response = new DataResponse();
		response.setCode(gcontactlist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gcontactlist != null ? "SUCCESS" : "团体没有通讯录信息");
		response.setData(contdata);
		renderJson(response);

	}
    /**
     * 得到职位下手机号码数量
     * @param mids 职位所属手机号码
     * @return
     */
    private Integer getContactsSnum(String mids)
    {
    	int snum=0;
    	if(mids!=null)
    	{
    		if(mids.indexOf(",")!=-1)
			{
    			snum=mids.split(",").length;
			}else if(mids.length()==11)
			{
				snum=1;
			}else
				snum=0;	
    	}
    	return snum;
    }

     
	/**
	 * 获取对外开放的所有团体通讯录数据
	 */
	public void getgroupcontactforisopenlists()
	{
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
	
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(groupid, "groupid can not be null")
				.put(mid, "mid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		List<GroupContactsModel> gcontactlist = GroupContactsModel.dao.find(GROUPCONTACTS_INFOLIST_SQL, groupid);
		//GROUPCONTACTS_ISOPENLIST_SQL
		List<GroupInfoModel> listgroup=GroupInfoModel.dao.find(QUERY_GROUPINFO);
		List<GroupIsOpenContactEntey> groupisopenlist=new ArrayList<GroupIsOpenContactEntey>();
		GroupIsOpenContactEntey giocen=new GroupIsOpenContactEntey();
		giocen.setN0(groupid);
		giocen.setN1("我们的通讯录");
		giocen.setN2(getGroupContactDataListByContList(gcontactlist));
		groupisopenlist.add(giocen);
		if(listgroup!=null)
		{
			for(GroupInfoModel ginfo:listgroup)
			{
				if(!ginfo.getStr(GroupInfoModel.ID).equals(groupid))
				{
					giocen=new GroupIsOpenContactEntey();
					giocen.setN0(ginfo.getStr(GroupInfoModel.ID));
					giocen.setN1(ginfo.getStr(GroupInfoModel.GNAME));
					gcontactlist= GroupContactsModel.dao.find(GROUPCONTACTS_ISOPENLIST_SQL, ginfo.getStr(GroupInfoModel.ID));
					giocen.setN2(getGroupContactDataListByContList(gcontactlist));
					groupisopenlist.add(giocen);
				}
			}
		}
	
		DataResponse response = new DataResponse();
		response.setCode(groupisopenlist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(groupisopenlist != null ? "SUCCESS" : "团体没有通讯录信息");

		response.setData(groupisopenlist);
		renderJson(response);
	}
	
	@SuppressWarnings("unused")
	private List<GroupContactEntey> getGroupContactDataListByContList(List<GroupContactsModel> gcontactlist)
	{
		List<GroupContactEntey> grcontactlist = null;
		GroupContactEntey gcontact = null;
		
		if(gcontactlist!=null)
		{
			grcontactlist=new ArrayList<GroupContactEntey>();
			for(GroupContactsModel gcm:gcontactlist)
			{
				gcontact = new GroupContactEntey();
				gcontact.setN0(gcm.getStr(GroupContactsModel.CNAMES));
				gcontact.setN1(gcm.getStr(GroupContactsModel.PARENTNAME));
				gcontact.setN3(gcm.getNumber(GroupContactsModel.VERSION)
						.intValue());
				gcontact.setN4(gcm.getNumber(GroupContactsModel.ORDERIDS)
						.intValue());
				gcontact.setN6(gcm.getStr(GroupContactsModel.ID));
				
				if(gcm.getStr(GroupContactsModel.MIDS)!=null)
				{
					if(gcm.getStr(GroupContactsModel.MIDS).indexOf(",")!=-1)
					{
						gcontact.setN2(gcm.getStr(GroupContactsModel.MIDS).split(",").length);
					}else if(gcm.getStr(GroupContactsModel.MIDS).length()==11)
					{
						gcontact.setN2(1);
					}else
						gcontact.setN2(0);
				}else
				{
					gcontact.setN2(0);
				}
				
				gcontact.setN5(null);
				grcontactlist.add(gcontact);
			}
			
		}
		
		return grcontactlist;
	}
	/**
	 * use contenst memberinfo list info
	 */
	public void getmemberinfolistbycid()
	{
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String cid =getPara("cid");// cid
		
		int size = getParaToInt("pagesize", 0);// 操作类型
		int cunpage = getParaToInt("curCount", 0);// 操作类型
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
					.put(did, "did can not be null")
				.put(size, "size can not be null")
				.put(cunpage, "cunpage can not be null")
				.put(cid, "cid can not be null"))) {
			return;
		}
		GroupContactsModel gcontactobj = GroupContactsModel.dao.findById(cid);
		String[] temp=null;
		String t="";
		List<GroupMemberSysSmsEntey> listmember=null;
		GroupMemberSysSmsEntey gminfo=null;
		GroupMemberinfoModel memberinfos=null;
		GroupMemberModel nowUser = null;//定义会员基础
		if(gcontactobj!=null)
		{
			listmember=new ArrayList<GroupMemberSysSmsEntey>();
			if(gcontactobj.getStr(GroupContactsModel.MIDS)!=null)
			{
				if(gcontactobj.getStr(GroupContactsModel.MIDS).indexOf(",")!=-1)
				{
					temp=gcontactobj.getStr(GroupContactsModel.MIDS).split(",");
					for(int i=0;i<temp.length;i++)
					{
						t=temp[i];
						//memberinfos=GroupMemberinfoModel.dao.findFirst(MEMBERINFOMIDSSQLCONT, t);
						//通过mid查询会员基础数据
						nowUser = GroupMemberModel.dao.findFirst("SELECT ids,realname,headimage,mids FROM y_group_member WHERE 1=1 and  mids='"+t+"'");
						memberinfos=GroupMemberinfoModel.dao.findFirst("SELECT * FROM y_group_memberinfo WHERE 1=1 and  mids='"+t+"'");
						if(nowUser!=null&&memberinfos!=null)
						 {
							 gminfo=new GroupMemberSysSmsEntey();
							 gminfo.setN0(nowUser.getStr(GroupMemberModel.ID));
	//						 gminfo.setN1(memberinfos.getStr(GroupMemberinfoModel.HEADIMAGE));
	//						 gminfo.setN2(memberinfos.getStr(GroupMemberinfoModel.REALNAME));
							 gminfo.setN1(nowUser.getStr(GroupMemberModel.HEADIMAGE));
							 gminfo.setN2(nowUser.getStr(GroupMemberModel.REALNAME));
							 GroupMemberCompanyModel gmcc=GroupMemberCompanyModel.dao.findFirst(MEMBER_COMPAYINGO_COUNT_SQL, t,groupid);
							 gminfo.setN3(gmcc!=null?gmcc.getStr(GroupMemberCompanyModel.COMNAME):Code.FINAL_STRING_COMPANY);
							 gminfo.setN4(nowUser.getStr(GroupMemberModel.MID));
							// gminfo.setN4(cungroupid!=null?nowUser.getStr(GroupMemberModel.MID).substring(0, 3)+"*******":nowUser.getStr(GroupMemberModel.MID));
							 listmember.add(gminfo);
						 }
						
					}
				}else if(gcontactobj.getStr(GroupContactsModel.MIDS).length()==11)
				{	
					t=gcontactobj.getStr(GroupContactsModel.MIDS);
					//memberinfos=GroupMemberinfoModel.dao.findFirst(MEMBERINFOMIDSSQLCONT, t);
					//通过mid查询会员基础数据
					nowUser = GroupMemberModel.dao.findFirst("SELECT ids,realname,headimage,mids FROM y_group_member WHERE 1=1 and  mids='"+t+"'");
					 if(nowUser!=null)
					 {
						 gminfo=new GroupMemberSysSmsEntey();
						 gminfo.setN0(nowUser.getStr(GroupMemberModel.ID));
	//					 gminfo.setN1(memberinfos.getStr(GroupMemberinfoModel.HEADIMAGE));
	//					 gminfo.setN2(memberinfos.getStr(GroupMemberinfoModel.REALNAME));
						 gminfo.setN1(nowUser.getStr(GroupMemberModel.HEADIMAGE));
						 gminfo.setN2(nowUser.getStr(GroupMemberModel.REALNAME));
						 GroupMemberCompanyModel gmcc=GroupMemberCompanyModel.dao.findFirst(MEMBER_COMPAYINGO_COUNT_SQL, t,groupid);
						 gminfo.setN3(gmcc!=null?gmcc.getStr(GroupMemberCompanyModel.COMNAME):Code.FINAL_STRING_COMPANY);
						 gminfo.setN4(nowUser.getStr(GroupMemberModel.MID));
						 listmember.add(gminfo);
					 }
					
				}else
				{
					listmember.add(null);
				}
			}
			
		}
		
		DataResponse response = new DataResponse();
		response.setCode(gcontactobj != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gcontactobj != null ? "SUCCESS" : "没有信息");

		response.setData(listmember);
		renderJson(response);
	}
	/**
	 * 获取会员公司集合 POST /api/group/getmembercompanylist
	 */
	public void getmembercompanylist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String fromgroupid = getPara("fromgroupid");// 查询团体所属的公司
		String frommid = getPara("frommid");// 类型ID
		int size = getParaToInt("pagesize", 0);// 分页大小

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null")
				.put(size, "pagesize can not be null"))) {
			return;
		}
		List<GroupMemberCompanyModel> gmclist = null;
		if (fromgroupid != null && frommid != null) {
			gmclist = GroupMemberCompanyModel.dao.find(MEMBER_COMPAYINGO_SQL,
					frommid, fromgroupid);
		} else {
			gmclist = GroupMemberCompanyModel.dao.find(
					MEMBER_COMPAYINGO_MID_SQL, mid);
		}

		List<GroupMemberCompanyEntey> listgmce = new ArrayList<GroupMemberCompanyEntey>();
		if (gmclist != null) {
			GroupMemberCompanyEntey gmce = null;
			for (GroupMemberCompanyModel gmcm : gmclist) {
				gmce = new GroupMemberCompanyEntey();
				gmce.setN0(gmcm.getStr(GroupMemberCompanyModel.ID));
				gmce.setN1(gmcm.getStr(GroupMemberCompanyModel.COMLOGO));
				gmce.setN2(gmcm.getStr(GroupMemberCompanyModel.COMNAME));
				gmce.setN11(gmcm.getStr(GroupMemberCompanyModel.COMMENTS));
				gmce.setN12(gmcm.getStr(GroupMemberCompanyModel.GROUPNAMES));
				listgmce.add(gmce);
			}

		}

		DataResponse response = new DataResponse();
		response.setCode(gmclist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gmclist != null ? "SUCCESS"
				: "会员无公司信息[查询参数:fromgroupid," + fromgroupid + "frommid,"
						+ frommid);
		response.setData(listgmce);
		renderJson(response);
	}
	/**
	 * 根据公司ID查询公司详情
	 */
	public void getmembercompanyinfobycid() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String comid = getPara("comid");// 公司ID
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null")
				.put(comid, "comid can not be null"))) {
			return;
		}
		GroupMemberCompanyModel gmcm=GroupMemberCompanyModel.dao.findById(comid);
		GroupMemberCompanyEntey gmce = new GroupMemberCompanyEntey();
		if(gmcm!=null)
		{
			gmce.setN0(gmcm.getStr(GroupMemberCompanyModel.ID));
			gmce.setN1(gmcm.getStr(GroupMemberCompanyModel.COMLOGO));
			gmce.setN2(gmcm.getStr(GroupMemberCompanyModel.COMNAME));
			gmce.setN3(gmcm.getStr(GroupMemberCompanyModel.COMDUTY));
			gmce.setN4(gmcm.getStr(GroupMemberCompanyModel.COMPROPERTY));
			gmce.setN5(gmcm.getStr(GroupMemberCompanyModel.COMSCALE));
			gmce.setN6(gmcm.getStr(GroupMemberCompanyModel.COMINDUSTRY));
			gmce.setN7(gmcm.getStr(GroupMemberCompanyModel.COMTEL));
			gmce.setN8(gmcm.getStr(GroupMemberCompanyModel.COMEMAIL));
			gmce.setN9(gmcm.getStr(GroupMemberCompanyModel.CADDRESS));
			gmce.setN10(gmcm.getStr(GroupMemberCompanyModel.COMURL));
			gmce.setN11(gmcm.getStr(GroupMemberCompanyModel.COMMENTS));
			gmce.setN12(gmcm.getStr(GroupMemberCompanyModel.GROUPNAMES));
			gmce.setN13(gmcm.getStr(GroupMemberCompanyModel.COMECURL));
		}
		DatumResponse response = new DatumResponse();
		response.setCode(gmcm != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gmcm != null ? "SUCCESS" : "没有公司详情");

		response.setDatum(gmce);
		renderJson(response);
	}
	/**
	 * 根据关键字搜索团体通讯录个人信息 POST /api/group/getmembercompanylist
	 */
	public void querybyvalueforgroupcontactlist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		SeachValue fb = null;
		String groupid=null,mid=null,did=null,likevalue=null;// 搜索关键字
		int size=0,cur=0;
		try {
			fb = getRepuestJosnObject(getRequest().getReader(), SeachValue.class);// 取出请求接口参数
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (fb != null) {
			groupid=fb.getGroupid();
			mid=fb.getMid();
			did=fb.getDid();
			cur=fb.getCurcount();
			size=fb.getPagesize();
			likevalue = fb.getLikevalue();
		}else
		{
			renderArgumentError("likevalue can not be null");
			return;
		}
		if (likevalue!=null&&StringUtils.isEmpty(likevalue)) {
			renderArgumentError("likevalue can not be null");
			return;
		}
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(groupid, "groupid can not be null")
				.put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(likevalue, "likevalue can not be null")
				.put(size, "pagesize can not be null"))) {
			return;
		}
		
		List<GroupContactEntey> grcontactlist = null;
		List<GroupMemberInfoEntey> gminfolist = null;
		GroupContactEntey gcontact = null;
		String querysql="SELECT * FROM (SELECT m.ids,m.mheadimage, m.realname,m.nikename,m.mids,m.mnativeplace,m.msex,m.mbirthday,m.orderids,ygc.cnames,ygc.orderids as ygcorder,ygc.version as ygcversion,ygc.parentname as ygcparentname from y_group_member s  right JOIN y_group_memberinfo  m  ON m.mids = s.mids INNER  JOIN y_group_contacts ygc ON find_in_set(m.mids,ygc.mids) where 1=1 AND s.status = 0 and FIND_IN_SET('"+groupid+"',s.groupids) and ygc.groupid='"+groupid+"' and m.realname like '%"+likevalue+"%' order BY ygcorder asc ) member ";
		//String querysql="SELECT * FROM (SELECT m.ids,s.headimage, s.realname,m.nikename,m.mids,m.mnativeplace,s.msex,m.mbirthday,m.orderids,ygc.cnames,ygc.orderids as ygcorder,ygc.version as ygcversion,ygc.parentname as ygcparentname from y_group_member s  right JOIN y_group_memberinfo  m  ON m.mids = s.mids INNER  JOIN y_group_contacts ygc ON find_in_set(m.mids,ygc.mids) where 1=1 AND s.status = 0 and FIND_IN_SET('"+groupid+"',s.groupids) and ygc.groupid='"+groupid+"' and m.realname like '%"+likevalue+"%' order BY ygcorder asc ) member ";
		
		List<GroupMemberinfoModel> gmilist=GroupMemberinfoModel.dao.find(querysql);
		
		if(gmilist!=null&&gmilist.size()>0)
		{
			GroupMemberinfoModel gmi=null;
			grcontactlist = new ArrayList<GroupContactEntey>();
			String tempcname=gmilist.get(0).getStr(GroupMemberinfoModel.CNAMES);
			gcontact = new GroupContactEntey();
			gcontact.setN0(tempcname);
			gcontact.setN1(gmilist.get(0).getStr(GroupMemberinfoModel.YGCPARENTNAME));
			gcontact.setN3(gmilist.get(0).getNumber(GroupMemberinfoModel.YGCVERSION)
					.intValue());
			gcontact.setN4(gmilist.get(0).getNumber(GroupMemberinfoModel.YGCORDER)
					.intValue());
			
			gminfolist=new ArrayList<GroupMemberInfoEntey>();
			GroupMemberInfoEntey gmientey=null;
			GroupMemberCompanyModel gmcc=null;

			int j=0;
			for(int i=0;i<gmilist.size();i++)
			{
				gmi=gmilist.get(i);
				if(tempcname.equals(gmi.getStr(GroupMemberinfoModel.CNAMES)))
				{
					j++;
				
				}else
				{
					//记录相同对象
					gcontact.setN2(j);
					gcontact.setN5(gminfolist);
					grcontactlist.add(gcontact);
					//新对象
					gminfolist=new ArrayList<GroupMemberInfoEntey>();
					tempcname=gmi.getStr(GroupMemberinfoModel.CNAMES);
					j=1;
					gcontact = new GroupContactEntey();
					gcontact.setN0(tempcname);
					gcontact.setN1(gmilist.get(0).getStr(GroupMemberinfoModel.YGCPARENTNAME));
					gcontact.setN3(gmilist.get(0).getNumber(GroupMemberinfoModel.YGCVERSION)
							.intValue());
					gcontact.setN4(gmilist.get(0).getNumber(GroupMemberinfoModel.YGCORDER)
							.intValue());
					
				}
				
				gmientey=new GroupMemberInfoEntey();
				gmientey.setN0(gmi.getStr(GroupMemberinfoModel.ID));
				gmientey.setN1(gmi.getStr(GroupMemberinfoModel.HEADIMAGE));
				gmientey.setN2(gmi.getStr(GroupMemberinfoModel.REALNAME));
		    	gmcc=GroupMemberCompanyModel.dao.findFirst(MEMBER_COMPAYINGO_SQL, gmi.getStr(GroupMemberinfoModel.MID),groupid);
		    	gmientey.setN3(gmcc!=null?gmcc.getStr(GroupMemberCompanyModel.COMNAME):Code.FINAL_STRING_COMPANY);
		    	gmientey.setN4(gmi.getStr(GroupMemberinfoModel.MID));
		    	gmientey.setN5(gmi.getStr(GroupMemberinfoModel.NATIVEPLACE));
		    	gmientey.setN6(gmi.getStr(GroupMemberinfoModel.SEX));
		    	gmientey.setN7(gmi.getStr(GroupMemberinfoModel.BIRTHDAY));
		    	gmientey.setN8(0);
		    	 
				gminfolist.add(gmientey);
			}
			//记录相同对象
			gcontact.setN2(j);
			gcontact.setN5(gminfolist);
			grcontactlist.add(gcontact);
			
		}
		
		DataResponse response = new DataResponse();
		response.setCode(gmilist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gmilist != null ? "SUCCESS" : "没找会员详情信息");
		response.setData(grcontactlist);
		renderJson(response);
	}
	/**
	 * 根据关键字搜索会员常用通讯录列表 POST /api/group/querycollectlist
	 */
	public void querycollectlist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		SeachValue fb = null;
		String groupid=null,mid=null,did=null,likevalue=null;// 搜索关键字
		int size=0,cur=0;
		
		try {
			fb = getRepuestJosnObject(getRequest().getReader(), SeachValue.class);// 取出请求接口参数
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (fb != null) {
			groupid=fb.getGroupid();
			mid=fb.getMid();
			did=fb.getDid();
			size=fb.getPagesize();
			cur=fb.getCurcount();
			likevalue = fb.getLikevalue();
		}else
		{
			renderArgumentError("likevalue can not be null");
			return;
		}
		if (StringUtils.isEmpty(likevalue)) {
			renderArgumentError("likevalue can not be null");
			return;
		}
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(did, "did can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(likevalue, "likevalue can not be null")
				.put(size, "pagesize can not be null"))) {
			return;
		}

		List<SystemCollectModel> conlist = SystemCollectModel.dao.find("SELECT * FROM y_system_collect WHERE mids='"+mid+"' AND collecttype="+did+"  AND  collectcomment like '%"+likevalue+"%' order by createtime  DESC LIMIT "+size);
		SystemCollectEntey gmcon = null;
		List<SystemCollectEntey> gmconlist = new ArrayList<SystemCollectEntey>();
		if (conlist != null) {
			for (SystemCollectModel gmcc : conlist) {
				gmcon = new SystemCollectEntey();
				gmcon.setN0(gmcc.getStr(SystemCollectModel.CIDS));
				gmcon.setN1(gmcc.getStr(SystemCollectModel.CVALUE));

				gmconlist.add(gmcon);
			}
		}

		DataResponse response = new DataResponse();
		response.setCode(conlist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(conlist != null ? "SUCCESS" : "无常用通讯录列表");
		response.setData(gmconlist);
		renderJson(response);
	}
	
	/**
	 * 获取会员发页的商机列表 POST /api/group/getmemberbusinessinfolist
	 */
	public void getmemberbusinessinfolist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String frommid = getPara("frommid");// 查询会员的手机号码

		int size = getParaToInt("pagesize", 0);// 分页大小

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(groupid, "groupid can not be null")
				.put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(size, "pagesize can not be null"))) {
			return;
		}
		List<GroupBusinessinfoModel> gbilist = null;
		if (frommid != null) {
			gbilist = GroupBusinessinfoModel.dao.find(
					MEMBERBI_GROUPIDANDMID_SQL, groupid, frommid, size);
		} else
			gbilist = GroupBusinessinfoModel.dao.find(
					MEMBERBI_GROUPIDANDMID_SQL, groupid, mid, size);

		MemberBusinessinfoEntey mbusinfo = null;
		List<MemberBusinessinfoEntey> listmbusinfo = new ArrayList<MemberBusinessinfoEntey>();
		if (gbilist != null) {
			GroupBusinessinfoBrowseModel gbbm = null;
			SystemPointlikeModel spm = null;
			SystemReviewModel srm = null;
			SystemCollectModel scm = null;
			GroupMemberModel nowUser=null;
			for (GroupBusinessinfoModel gbusinfo : gbilist) {
				mbusinfo = new MemberBusinessinfoEntey();
				mbusinfo.setN0(gbusinfo.getStr(GroupBusinessinfoModel.ID));
				mbusinfo.setN1(gbusinfo.getStr(GroupBusinessinfoModel.BIIAMGES));
				mbusinfo.setN2(gbusinfo.getStr(GroupBusinessinfoModel.BITITLE));
				mbusinfo.setN3(DateUtils.format(gbusinfo.getDate(GroupBusinessinfoModel.CREATETIME),
						"yyyy-MM-dd"));
//				GroupMemberinfoModel userinfo = GroupMemberinfoModel.dao
//						.findFirst(MEMBERINFOMIDSSQL,
//								gbusinfo.getStr(GroupBusinessinfoModel.MID));
				//通过mid查询会员基础数据
				nowUser = GroupMemberModel.dao.
						findFirst(MEMBERMIDSSQL,gbusinfo.getStr(GroupBusinessinfoModel.MID));
//				mbusinfo.setN4(userinfo != null ? userinfo
//						.getStr(GroupMemberinfoModel.REALNAME)
//						: Code.FINAL_STRING_MEMBER);
				mbusinfo.setN4(nowUser != null ? nowUser
						.getStr(GroupMemberModel.REALNAME)
						: Code.FINAL_STRING_MEMBER);
				GroupInfoModel groupinfo = GroupInfoModel.dao.findFirst(
						GROUPINFOBYIDSQL,
						gbusinfo.getStr(GroupBusinessinfoModel.GROUPIDS));
				mbusinfo.setN5(groupinfo != null ? groupinfo
						.getStr(GroupInfoModel.GNAME) : Code.FINAL_STRING_GROUP);
				GroupContactsModel gcontacts = GroupContactsModel.dao
						.findFirst(GROUPCONTACTS_MID_QUERY_SQL,
								gbusinfo.getStr(GroupBusinessinfoModel.MID));
				mbusinfo.setN6(gcontacts != null ? gcontacts
						.getStr(GroupContactsModel.CNAMES)
						: Code.FINAL_STRING_CONTE);
				gbbm = GroupBusinessinfoBrowseModel.dao.findFirst(
						GROUPBUSINESSINFOBROWSE_SUMNUMBER_SQL, gbusinfo.getStr(GroupBusinessinfoModel.ID));
				mbusinfo.setN7(gbbm != null ? gbbm.getNumber(
						GroupBusinessinfoBrowseModel.SCOUNT).intValue() : 0);
				srm = SystemReviewModel.dao.findFirst(
						GET_REVIEW_SUMNUMBER_SQL,
						groupid,
						did,gbusinfo.getStr(GroupBusinessinfoModel.ID));
				mbusinfo.setN8(srm != null ? srm.getNumber(
						SystemReviewModel.SCOUNT).intValue() : 0);
				spm = SystemPointlikeModel.dao.findFirst(
						GET_POINTLIKE_SUMNUMBER_SQL,
						groupid,
						did,gbusinfo.getStr(GroupBusinessinfoModel.ID));
				mbusinfo.setN9(spm != null ? spm.getNumber(
						SystemPointlikeModel.SCOUNT).intValue() : 0);
				spm = SystemPointlikeModel.dao.findFirst(
						GET_POINTLIKE_ISOPEN_SQL,
						groupid,
						did,gbusinfo.getStr(GroupBusinessinfoModel.ID), mid);
				mbusinfo.setN10(spm != null ? 0 : 1);
				scm = SystemCollectModel.dao.findFirst(
						SYSTEMCOLLECT_ISCOLL_SQL,
						groupid,
						did,gbusinfo.getStr(GroupBusinessinfoModel.ID), mid);
				mbusinfo.setN11(scm != null ? 0 : 1);

				listmbusinfo.add(mbusinfo);
			}

		}

		DataResponse response = new DataResponse();
		response.setCode(gbilist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gbilist != null ? "SUCCESS" : "会员没有发布的商机信息");
		response.setData(listmbusinfo);
		renderJson(response);
	}


	/**
	 * 获取团体商机列表 POST /api/group/getgroupbusinessinfolist?groupid=
	 * 88888888888888888888888888888888
	 * &mid=13540148430&did=66666&pagesize=10&type
	 * =0&token=59b8a19bf5c846708715f6166bad0c49e36BLF
	 */
	public void getgroupbusinessinfolist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int type = getParaToInt("type", 0);// 0苯团体1全国所有团体商机列表
		int size = getParaToInt("pagesize", 0);// 分页大小
		int cun = getParaToInt("curCount", 0);// 当前数据量
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(size, "pagesize can not be null")
				.put(groupid, "groupid can not be null")
				.put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(type, "type can not be null"))) {
			return;
		}
		MemberBusinessListEntey mblistentey = null;

		List<GroupBusinessinfoModel> groupbusinfo = null;
		List<GroupBusinessinfoModel> top5groupbusinfo = null;
		if (type == 0) {
			top5groupbusinfo=GroupBusinessinfoModel.dao.find(MEMBERBI_GROUPID_TOP5_SQL, groupid);
			groupbusinfo = GroupBusinessinfoModel.dao.find(MEMBERBI_GROUPID_LIST_SQL, groupid,cun, cun+size);
		} else {
			groupbusinfo = GroupBusinessinfoModel.dao.find(MEMBERBI_ALL_SQL,size);
			top5groupbusinfo=GroupBusinessinfoModel.dao.find(MEMBERBI_ALL_TOP5_SQL);
		}

		if (groupbusinfo != null && top5groupbusinfo!=null) {
			mblistentey = new MemberBusinessListEntey();
			List<MemberBusinessinfoTopFiveEntey> topfivelist = new ArrayList<MemberBusinessinfoTopFiveEntey>();
			MemberBusinessinfoTopFiveEntey topfive = null;
			MemberBusinessinfoEntey mbusinfo = null;
			GroupBusinessinfoBrowseModel gbbm = null;
			SystemPointlikeModel spm = null;
			SystemReviewModel srm = null;
			SystemCollectModel scm = null;
			List<MemberBusinessinfoEntey> mbusinfolist = new ArrayList<MemberBusinessinfoEntey>();
			//存放顶部数据
			for(int j=0;j<top5groupbusinfo.size();j++)
			{
				//thisItem.n5,thisItem.n3,thisItem.n4,thisItem.n7,thisItem.n8,thisItem.n9
				topfive = new MemberBusinessinfoTopFiveEntey();
				//GroupMemberinfoModel userinfo = GroupMemberinfoModel.dao.findFirst(MEMBERINFOMIDSSQL, top5groupbusinfo.get(j).getStr(GroupBusinessinfoModel.MID));
				//通过mid查询会员基础数据
				GroupMemberModel nowUser = GroupMemberModel.dao.findFirst(MEMBERMIDSSQL,top5groupbusinfo.get(j).getStr(GroupBusinessinfoModel.MID));
				
				
				GroupInfoModel groupinfo = GroupInfoModel.dao.findFirst(GROUPINFOBYIDSQL,top5groupbusinfo.get(j).getStr(GroupBusinessinfoModel.GROUPIDS));
				gbbm=GroupBusinessinfoBrowseModel.dao.findFirst(GROUPBUSINESSINFOBROWSE_SUMNUMBER_SQL, top5groupbusinfo.get(j).getStr(GroupBusinessinfoModel.ID));
				srm = SystemReviewModel.dao.findFirst(GET_REVIEW_SUMNUMBER_SQL,groupid,did,top5groupbusinfo.get(j).getStr(GroupBusinessinfoModel.ID));
				spm = SystemPointlikeModel.dao.findFirst(GET_POINTLIKE_SUMNUMBER_SQL,groupid,did,top5groupbusinfo.get(j).getStr(GroupBusinessinfoModel.ID));
				topfive.setN0(top5groupbusinfo.get(j).getStr(GroupBusinessinfoModel.ID));				
				topfive.setN1(top5groupbusinfo.get(j).getStr(
						GroupBusinessinfoModel.BIIAMGES));
				topfive.setN2(top5groupbusinfo.get(j)
						.getNumber(GroupBusinessinfoModel.ORDERIDS)
						.intValue());
				topfive.setN3(top5groupbusinfo.get(j).getStr(GroupBusinessinfoModel.BITITLE));
				topfive.setN4(groupinfo != null ? groupinfo.getStr(GroupInfoModel.GNAME): Code.FINAL_STRING_GROUP);
				topfive.setN5(DateUtils.format(top5groupbusinfo.get(j).getDate(GroupBusinessinfoModel.CREATETIME),"yyyy-MM-dd"));
//				topfive.setN6(userinfo != null ? userinfo.getStr(GroupMemberinfoModel.REALNAME): Code.FINAL_STRING_MEMBER);
				topfive.setN6(nowUser != null ? nowUser.getStr(GroupMemberModel.REALNAME): Code.FINAL_STRING_MEMBER);
				topfive.setN7(gbbm != null ? gbbm.getNumber(GroupBusinessinfoBrowseModel.SCOUNT).intValue():0);
				topfive.setN8(srm != null ? srm.getNumber(SystemReviewModel.SCOUNT).intValue():0);
				topfive.setN9(spm != null ? spm.getNumber(SystemPointlikeModel.SCOUNT).intValue():0);
				scm = SystemCollectModel.dao.findFirst(
						SYSTEMCOLLECT_ISCOLL_SQL,
						groupid,
						did,
						top5groupbusinfo.get(j).getStr(
								GroupBusinessinfoModel.ID), mid);
				topfive.setN10(scm != null ? 0 : 1);
				topfivelist.add(topfive);
				mblistentey.setN0(topfivelist);
			}
			//存放列表数据
			for (int i = 0; i < groupbusinfo.size(); i++) {
					mbusinfo = new MemberBusinessinfoEntey();
					mbusinfo.setN0(groupbusinfo.get(i).getStr(
							GroupBusinessinfoModel.ID));
					mbusinfo.setN1(groupbusinfo.get(i).getStr(
							GroupBusinessinfoModel.BIIAMGES));
					mbusinfo.setN2(groupbusinfo.get(i).getStr(
							GroupBusinessinfoModel.BITITLE));
					mbusinfo.setN3(DateUtils.format(groupbusinfo.get(i)
							.getDate(GroupBusinessinfoModel.CREATETIME),
							"yyyy-MM-dd"));
					//GroupMemberinfoModel userinfo = GroupMemberinfoModel.dao
							//.findFirst(MEMBERINFOMIDSSQL, groupbusinfo.get(i)
									//.getStr(GroupBusinessinfoModel.MID));
					//通过mid查询会员基础数据
					GroupMemberModel nowUser = GroupMemberModel.dao.
							findFirst(MEMBERMIDSSQL,groupbusinfo.get(i)
									.getStr(GroupBusinessinfoModel.MID));
					
//					mbusinfo.setN4(userinfo != null ? userinfo
//							.getStr(GroupMemberinfoModel.REALNAME)
//							: Code.FINAL_STRING_MEMBER);
					mbusinfo.setN4(nowUser != null ? nowUser
							.getStr(GroupMemberModel.REALNAME)
							: Code.FINAL_STRING_MEMBER);
					GroupInfoModel groupinfo = GroupInfoModel.dao.findFirst(
							GROUPINFOBYIDSQL,
							groupbusinfo.get(i).getStr(
									GroupBusinessinfoModel.GROUPIDS));
					mbusinfo.setN5(groupinfo != null ? groupinfo
							.getStr(GroupInfoModel.GNAME)
							: Code.FINAL_STRING_GROUP);
					GroupContactsModel gcontacts = GroupContactsModel.dao
							.findFirst(
									GROUPCONTACTS_MID_QUERY_SQL,
									groupbusinfo.get(i).getStr(
											GroupBusinessinfoModel.MID));
					mbusinfo.setN6(gcontacts != null ? gcontacts
							.getStr(GroupContactsModel.CNAMES)
							: Code.FINAL_STRING_CONTE);
					gbbm = GroupBusinessinfoBrowseModel.dao.findFirst(
							GROUPBUSINESSINFOBROWSE_SUMNUMBER_SQL, groupbusinfo
									.get(i).getStr(GroupBusinessinfoModel.ID));
					mbusinfo.setN7(gbbm != null ? gbbm.getNumber(
							GroupBusinessinfoBrowseModel.SCOUNT).intValue() : 0);
					srm = SystemReviewModel.dao.findFirst(
							GET_REVIEW_SUMNUMBER_SQL,
							groupid,
							did,
							groupbusinfo.get(i).getStr(
									GroupBusinessinfoModel.ID));
					mbusinfo.setN8(srm != null ? srm.getNumber(
							SystemReviewModel.SCOUNT).intValue() : 0);
					spm = SystemPointlikeModel.dao.findFirst(
							GET_POINTLIKE_SUMNUMBER_SQL,
							groupid,
							did,
							groupbusinfo.get(i).getStr(
									GroupBusinessinfoModel.ID));
					mbusinfo.setN9(spm != null ? spm.getNumber(
							SystemPointlikeModel.SCOUNT).intValue() : 0);
					spm = SystemPointlikeModel.dao.findFirst(
							GET_POINTLIKE_ISOPEN_SQL,
							groupid,
							did,
							groupbusinfo.get(i).getStr(
									GroupBusinessinfoModel.ID), mid);
					mbusinfo.setN10(spm != null ? 0 : 1);
					scm = SystemCollectModel.dao.findFirst(
							SYSTEMCOLLECT_ISCOLL_SQL,
							groupid,
							did,
							groupbusinfo.get(i).getStr(
									GroupBusinessinfoModel.ID), mid);
					mbusinfo.setN11(scm != null ? 0 : 1);
					mbusinfolist.add(mbusinfo);
					mblistentey.setN1(mbusinfolist);
			}
		}
		List<SystemJpushUrlInfoModel> listsjuim=SystemJpushUrlInfoModel.dao.find("select * from y_system_jpush_urlinfo where 1=1 and  groupid=? and type=?", groupid,4);
		if(listsjuim!=null)
		{
			for(SystemJpushUrlInfoModel sjum:listsjuim)
			{
				new SystemJpushUserReadInfoModel().set(SystemJpushUserReadInfoModel.ID, getCreateUUId())
				.set(SystemJpushUserReadInfoModel.MIDS, mid)
				.set(SystemJpushUserReadInfoModel.PUSHIDS, sjum.getStr(SystemJpushUrlInfoModel.ID)).set(SystemJpushUserReadInfoModel.CREATETIME, DateUtils.getDate()).save();
			}
		}
		DatumResponse response = new DatumResponse();
		response.setCode(groupbusinfo != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(groupbusinfo != null ? "SUCCESS" : "无团体商机列表");
		response.setDatum(mblistentey);
		renderJson(response);
	}

	/**
	 * 获取团体商机详细信息 POST /api/group/getgroupbusinessinfobybid
	 */
	public void getgroupbusinessinfobybid() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID

		String bid = getPara("bid");// 商机ID

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(bid, "bid can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		GroupBusinessinfoModel groupbusinfo = GroupBusinessinfoModel.dao
				.findById(bid);
		MemeberBuinessinfoCommentEntey comment = new MemeberBuinessinfoCommentEntey();
		if (groupbusinfo != null) {
			comment.setN0(groupbusinfo.getStr(GroupBusinessinfoModel.BIIAMGES));
			comment.setN1(groupbusinfo.getStr(GroupBusinessinfoModel.BICNAME));
			comment.setN2(groupbusinfo.getStr(GroupBusinessinfoModel.BICTEL));
			comment.setN3(groupbusinfo.getStr(GroupBusinessinfoModel.BITRADE));
			comment.setN4(groupbusinfo.getStr(GroupBusinessinfoModel.BIADDRESS));
			comment.setN5(groupbusinfo
					.getStr(GroupBusinessinfoModel.BIVALIDITY));
			comment.setN6(groupbusinfo.getStr(GroupBusinessinfoModel.BICOMMENT));

			comment.setN7(groupbusinfo.getStr(GroupBusinessinfoModel.MID));
		//	GroupMemberinfoModel userinfo = GroupMemberinfoModel.dao.findFirst(
					//MEMBERINFOMIDSSQL,
				//	groupbusinfo.getStr(GroupBusinessinfoModel.MID));
			//通过mid查询会员基础数据
			GroupMemberModel nowUser = GroupMemberModel.dao.
					findFirst(MEMBERMIDSSQL,groupbusinfo.getStr(GroupBusinessinfoModel.MID));
			comment.setN8(nowUser != null ? nowUser
					.getStr(GroupMemberModel.REALNAME)
					: Code.FINAL_STRING_MEMBER);

			List<GroupBusinessinfoBrowseModel> browselist = GroupBusinessinfoBrowseModel.dao
					.find(MEMBERBIBROWSE_ALL_SQL, bid);
			List<SystemCollectEntey> browseobecjtlist = null;
			if (browselist != null) {
				browseobecjtlist = new ArrayList<SystemCollectEntey>();
				SystemCollectEntey sce = null;
				for (GroupBusinessinfoBrowseModel gbb : browselist) {
					sce = new SystemCollectEntey();
					sce.setN0(gbb.getStr(GroupBusinessinfoBrowseModel.MID));
					sce.setN1(gbb
							.getStr(GroupBusinessinfoBrowseModel.MHEADIMAGE));

					browseobecjtlist.add(sce);
				}
			}
			comment.setN9(browseobecjtlist);

		}
		//GroupMemberinfoModel minfo = GroupMemberinfoModel.dao.findFirst(
			//	MEMBERINFOMIDSSQL, mid);
		//通过mid查询会员基础数据
		GroupMemberModel nowUser = GroupMemberModel.dao.findFirst(MEMBERMIDSSQL,mid);
		// 记录用户打开商机详情
		new GroupBusinessinfoBrowseModel()
				.set(GroupBusinessinfoBrowseModel.ID, getCreateUUId())
				.set(GroupBusinessinfoBrowseModel.VERSION, 0)
				.set(GroupBusinessinfoBrowseModel.ORDERIDS, 0)
				.set(GroupBusinessinfoBrowseModel.MID, mid)
//				.set(GroupBusinessinfoBrowseModel.MHEADIMAGE,
//						minfo != null ? minfo
//								.getStr(GroupMemberinfoModel.HEADIMAGE) : "")
				.set(GroupBusinessinfoBrowseModel.MHEADIMAGE,
						nowUser != null ? nowUser
								.getStr(GroupMemberModel.HEADIMAGE) : "")
				.set(GroupBusinessinfoBrowseModel.BIIDS, bid)
				.set(GroupBusinessinfoBrowseModel.CREATETIME,
						DateUtils.getDate()).save();

		DatumResponse response = new DatumResponse();
		response.setCode(groupbusinfo != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(groupbusinfo != null ? "SUCCESS" : "无团体商机详情");
		response.setDatum(comment);
		renderJson(response);
	}

	/**
	 * 获取商机详情互动数据 POST /api/group/getTop5buessinfobyAction
	 */
	public void getTop5buessinfobyAction() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String bid = getPara("bid");// 商机ID

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(bid, "bid can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		GroupBusessAction gba = new GroupBusessAction();

		SystemPointlikeModel spm = null;
		SystemReviewModel srm = null;
		SystemCollectModel scm = null;
		GroupBusinessinfoBrowseModel gbbm = null;
		// 获取商机互动数据
		gbbm = GroupBusinessinfoBrowseModel.dao.findFirst(
				GROUPBUSINESSINFOBROWSE_SUMNUMBER_SQL, bid);
		gba.setN0(gbbm != null ? gbbm.getNumber(
				GroupBusinessinfoBrowseModel.SCOUNT).intValue() : 0);
		srm = SystemReviewModel.dao.findFirst(GET_REVIEW_SUMNUMBER_SQL,
				groupid, did, bid);
		gba.setN1(srm != null ? srm.getNumber(SystemReviewModel.SCOUNT)
				.intValue() : 0);
		spm = SystemPointlikeModel.dao.findFirst(GET_POINTLIKE_SUMNUMBER_SQL,
				groupid, did, bid);
		gba.setN2(spm != null ? spm.getNumber(SystemPointlikeModel.SCOUNT)
				.intValue() : 0);
		spm = SystemPointlikeModel.dao.findFirst(GET_POINTLIKE_ISOPEN_SQL,
				groupid, did, bid, mid);
		gba.setN3(spm != null ? 0 : 1);
		scm = SystemCollectModel.dao.findFirst(SYSTEMCOLLECT_ISCOLL_SQL,
				groupid, did, bid, mid);
		gba.setN4(scm != null ? 0 : 1);

		DatumResponse response = new DatumResponse();
		response.setCode(gba != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gba != null ? "SUCCESS" : "无团体商机详情");
		response.setDatum(gba);
		renderJson(response);

	}

	/**
	 * 会员发布商机信息 POST /api/group/sendgroupbusinessinfo
	 */
	public void sendgroupbusinessinfo() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid =null,mid=null,did=null;// 团体ID// 会员手机号码// 类型ID
		GroupBusessInfo gbinfo = null;
		try {
			gbinfo = getRepuestJosnObject(getRequest().getReader(),
					GroupBusessInfo.class);// 取出请求接口参数
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(gbinfo!=null)
		{
			groupid=gbinfo.getGroupid();
			mid=gbinfo.getMid();
			did=gbinfo.getDid();
		}else {
			return;
		}
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		GroupBusinessinfoModel gbfm = GroupBusinessinfoModel.dao.findFirst(
				MEMBERBI_ORDERIDS_SQL, groupid);
		boolean flag = new GroupBusinessinfoModel()
				.set(GroupBusinessinfoModel.ID, getCreateUUId())
				.set(GroupBusinessinfoModel.GROUPIDS, groupid)
				.set(GroupBusinessinfoModel.MID, mid)
				.set(GroupBusinessinfoModel.BICNAME, gbinfo.getBicontactname())
				.set(GroupBusinessinfoModel.BICTEL, gbinfo.getBicontacttell())
				.set(GroupBusinessinfoModel.BITRADE, gbinfo.getBicontacttrade())
				.set(GroupBusinessinfoModel.BIADDRESS,
						gbinfo.getBicontactaddress())
				.set(GroupBusinessinfoModel.BIVALIDITY,
						gbinfo.getBicontactvalidity())
				.set(GroupBusinessinfoModel.BITITLE, gbinfo.getBititle())
				.set(GroupBusinessinfoModel.BICOMMENT, gbinfo.getBicommnet())
				.set(GroupBusinessinfoModel.BIIAMGES, gbinfo.getBiimages())
				.set(GroupBusinessinfoModel.ISOPEN, gbinfo.getIsopen())
				.set(GroupBusinessinfoModel.CREATETIME, DateUtils.getDate())
				.set(GroupBusinessinfoModel.ORDERIDS,
						gbfm != null ? (gbfm.getNumber(
								GroupBusinessinfoModel.ORDERIDS).intValue() + 1)
								: 1).set(GroupBusinessinfoModel.VERSION, 0)
				.save();
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL,
				flag ? Code.FINAL_STRING_SUCCESS : Code.FINAL_STRING_ERROR));
	}

	/**
	 * 会员发布商机信息 POST /api/group/sendgroupbusinessinfoapp
	 */
	@SuppressWarnings("unchecked")
	public void sendgroupbusinessinfoforapp() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		Map<String,Object> imgmap=null;
		boolean flag=false;
		Map<String, Object> jsonObj =null;
		String infoMap =null;;
		String busimageurl="";
		List<UploadFile> fileList = getFiles();//已接收到的文件
		if(fileList != null && !fileList.isEmpty()){
		    Map<String, String> urls = new HashMap<String, String>();//用于保存上传成功的文件地址
			List<String> failedFiles = new ArrayList<String>(); //用于保存未成功上传的文件名
            
            for(UploadFile uploadFile : fileList){
				File file=uploadFile.getFile();
			
				imgmap = FileUtils.saveUploadFile(file,IMGSize.X640.value());
                if (!imgmap.get("msg").equals("100")) {
                    failedFiles.add(uploadFile.getParameterName());//标记为上传失败
                } else {
                	busimageurl+=imgmap.get("imgsrc_slt").toString()+",";
                    //返回相对路径,用于响应
                    urls.put(uploadFile.getParameterName(), imgmap.get("imgsrc_slt").toString());
                }
			}
		}
		
		try {
			infoMap= URLDecoder.decode(getRequest().getParameter("infoMap"), "UTF-8");
			jsonObj=JsonObjectUtil.mapper.readValue(infoMap, Map.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(jsonObj!=null)
		{
			GroupBusinessinfoModel gbfm = GroupBusinessinfoModel.dao.findFirst(
					MEMBERBI_ORDERIDS_SQL, jsonObj.get("groupid"));
			infoMap=getCreateUUId();
			flag = new GroupBusinessinfoModel()
					.set(GroupBusinessinfoModel.ID, infoMap)
					.set(GroupBusinessinfoModel.GROUPIDS, jsonObj.get("groupid"))
					.set(GroupBusinessinfoModel.MID, jsonObj.get("mid"))
					.set(GroupBusinessinfoModel.BICNAME, jsonObj.get("bicontactname"))
					.set(GroupBusinessinfoModel.BICTEL, jsonObj.get("bicontacttell"))
					.set(GroupBusinessinfoModel.BITRADE, jsonObj.get("bicontacttrade"))
					.set(GroupBusinessinfoModel.BIADDRESS,jsonObj.get("bicontactaddress"))
					.set(GroupBusinessinfoModel.BIVALIDITY,jsonObj.get("bicontactvalidity"))
					.set(GroupBusinessinfoModel.BITITLE, jsonObj.get("bititle"))
					.set(GroupBusinessinfoModel.BICOMMENT, jsonObj.get("bicommnet"))
					.set(GroupBusinessinfoModel.BIIAMGES, busimageurl.substring(0,busimageurl.length()-1))
					.set(GroupBusinessinfoModel.ISOPEN, jsonObj.get("isopen"))
					.set(GroupBusinessinfoModel.CREATETIME, DateUtils.getDate())
					.set(GroupBusinessinfoModel.ORDERIDS,
							gbfm != null ? (gbfm.getNumber(
									GroupBusinessinfoModel.ORDERIDS).intValue() + 1)
									: 1).set(GroupBusinessinfoModel.VERSION, 0)
					.save();
			infoMap="infoid="+infoMap+"&title="+jsonObj.get("bititle")+"&desc="+(jsonObj.get("bicommnet").toString().length()>20?jsonObj.get("bicommnet").toString().substring(0, 20):jsonObj.get("bicommnet").toString())+"&isColltect=0";
		}
		
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL,
				flag ? Code.FINAL_STRING_SUCCESS : Code.FINAL_STRING_ERROR));
		if(flag)
		{
			busimageurl=getCreateUUId();
			//保存推送信息访问地址
			new SystemJpushUrlInfoModel().set(SystemJpushUrlInfoModel.ID, busimageurl)
			.set(SystemJpushUrlInfoModel.GROUPID, jsonObj.get("groupid"))
			.set(SystemJpushUrlInfoModel.TYPE, 4)
			.set(SystemJpushUrlInfoModel.WEBURL, "/cocapi/app/html/first_frame/busess_info.html")
			.set(SystemJpushUrlInfoModel.REQPARAM, infoMap)
			.set(SystemJpushUrlInfoModel.CREATETIME,DateUtils.getDate()).save();

			PushUtils.busSendPush(jsonObj.get("groupid").toString(),busimageurl,"商会发布了一条新的商机信息",null);
		}
	}
	public void delbusinfobybid()
	{
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String bid = getPara("bid");// 商机ID

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(bid, "bid can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		boolean flag = GroupBusinessinfoModel.dao.deleteById(bid);
		// 返回数据
        renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL, flag ? Code.FINAL_STRING_SUCCESS: Code.FINAL_STRING_ERROR));
	}
	/**
	 * 获取行业列表是否有更新 POST /api/group/gettradeisupdate
	 */
	public void gettradeisupdate() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int lvnmb = getParaToInt("localContactCacheVersion", 0);// 缓存最大号

		// 校验参数, 确保不能为空
		if (!notNull(Require.me()
				.put(lvnmb, "localContactCacheVersion can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		BasicDictModel GCM = BasicDictModel.dao.findFirst(
				TRADE_MAX_VERSION_SQL, did);
		// 返回数据
		renderJson(new BaseResponse(Code.SUCCESS, lvnmb == GCM.getNumber(
				BasicDictModel.VERSION).intValue() ? Code.FINAL_STRING_EORR
				: Code.FINAL_STRING_SUSS));
	}

	/**
	 * 获取行业列表 POST /api/group/gettradelist
	 */
	public void gettradelist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int size = getParaToInt("pagesize", 0);// 分页大小

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(size, "pagesize can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		List<BasicTradeModel> conlist = BasicTradeModel.dao.find(TRADE_LIST_SQL, size);
		List<SystemTradeEntey> listtrade = null;
		if (conlist != null) {
			listtrade = new ArrayList<SystemTradeEntey>();
			SystemTradeEntey ste = null;
			for (BasicTradeModel bdm : conlist) {
				ste = new SystemTradeEntey();
				ste.setN0(bdm.getStr(BasicTradeModel.ID));
				ste.setN1(bdm.getStr(BasicTradeModel.TNAME));
				ste.setN2(bdm.getNumber(BasicTradeModel.VERSION).intValue());
				ste.setN3(Integer.valueOf(bdm.getStr(BasicTradeModel.ORDERIDS)));

				listtrade.add(ste);
			}
		}
		DataResponse response = new DataResponse();
		response.setCode(conlist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(conlist != null ? "SUCCESS" : "无行业列表");
		response.setData(listtrade);
		renderJson(response);
	}
	/**
	 * 获取会员常用行业信息（默认用户有5个行业标签） POST /api/group/getMemberTradeinfo
	 */
	public void getMemberTradeinfo()
	{
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		GroupMemberLabelModel gmlm=GroupMemberLabelModel.dao.findFirst(MEMBER_TRADE_LIST_SQL, groupid,mid,did);
		boolean flag=gmlm!=null?true:false;
		
		// 返回数据
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL,
				flag ? gmlm.getStr(GroupMemberLabelModel.LABELVALUE) : Code.FINAL_STRING_ERROR));
		
	}
	/**
	 * 编辑常用行业信息（默认用户有5个行业标签） POST /api/group/savemembertradelabel
	 */
	public void savemembertradelabel() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String labelvalue=null;// 行业值
		Trade fb = null;
		try {
			fb = getRepuestJosnObject(getRequest().getReader(), Trade.class);// 取出请求接口参数
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (fb != null) {
			labelvalue=fb.getLabelvalue();
		}else
			return;
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(labelvalue, "labelvalue can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		GroupMemberLabelModel gmlm=GroupMemberLabelModel.dao.findFirst(MEMBER_TRADE_LIST_SQL, groupid,mid,did);
		// 保存数据
		boolean flag=false;
		if(gmlm!=null)
		{
			gmlm.set(GroupMemberLabelModel.LABELVALUE, labelvalue);
			gmlm.set(GroupMemberLabelModel.UPDATETIME,  DateUtils.getDate());
			flag=gmlm.update();
			
		}else
		{
			flag= new GroupMemberLabelModel()
					.set(GroupMemberLabelModel.ID, getCreateUUId())
					.set(GroupMemberLabelModel.VERSION, 0)
					.set(GroupMemberLabelModel.ORDERIDS, 0)
					.set(GroupMemberLabelModel.GROUPID, groupid)
					.set(GroupMemberLabelModel.MID, mid)
					.set(GroupMemberLabelModel.DICTNAME, did)
					.set(GroupMemberLabelModel.LABELVALUE, labelvalue)
					.set(GroupMemberLabelModel.CREATETIME, DateUtils.getDate())
					.save();
		}

		// 返回数据
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL,
				flag ? Code.FINAL_STRING_SUCCESS : Code.FINAL_STRING_ERROR));

	}

	/**
	 * 根据会员所选行业或关键字查询商机列表 POST /api/group/getgroupbusinessinfobytradelist
	 */
	public void getgroupbusinessinfobytradelist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = null;// 团体ID
		String mid = null;// 会员手机号码
		String did = null;// 类型ID
		String trade = getPara("trade");// 行业
		int size = 0;// 分页大小
		int type = 0;// 查询范围
		int curcount=0;
		List<GroupBusinessinfoModel> groupbusinfo = null;
		SeachValue fb = null;
		String likevalue=null;// 搜索关键字
		try {
			fb = getRepuestJosnObject(getRequest().getReader(), SeachValue.class);// 取出请求接口参数
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (fb != null) {
			likevalue = fb.getLikevalue();
			groupid=fb.getGroupid();
			mid=fb.getMid();
			did=fb.getDid();
			type=fb.getType();
			size=fb.getPagesize();
			curcount=fb.getCurcount();
		}else
		{
			renderArgumentError("likevalue can not be null");
			return;
		}
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(size, "pagesize can not be null")
				.put(type, "type can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		if (type == 0) {
			if (likevalue != null && trade != null) {
				groupbusinfo = GroupBusinessinfoModel.dao.find(
						MEMBERBI_TRADEANDLIKEVALUE_SQL, groupid, likevalue,
						trade, size);
			} else if (likevalue != null) {
				groupbusinfo = GroupBusinessinfoModel.dao.find(
						"SELECT * FROM y_group_businessinfo WHERE 1=1 AND status = 0  AND groupid='"+groupid+"' AND  bititle like '%"+likevalue+"%'  order by orderids limit "+curcount+","+curcount+size);
			} else if (trade != null) {
				groupbusinfo = GroupBusinessinfoModel.dao.find(
						MEMBERBI_GROUPID_LIST_SQL, groupid, size);
			} else {
				groupbusinfo = GroupBusinessinfoModel.dao.find(
						MEMBERBI_GROUPID_LIST_SQL, groupid, size);
			}

		} else {
			if (likevalue != null && trade != null) {
				groupbusinfo = GroupBusinessinfoModel.dao.find(
						"SELECT * FROM y_group_businessinfo WHERE 1=1 AND status = 0 AND isopen=0  AND  bititle like '%"+likevalue+"%'  order by orderids limit "+curcount+","+curcount+size);
			} else if (likevalue != null) {
				groupbusinfo = GroupBusinessinfoModel.dao.find(
						"SELECT * FROM y_group_businessinfo WHERE 1=1 AND status = 0 AND isopen=0  AND  bititle like '%"+likevalue+"%'  order by orderids limit "+curcount+","+curcount+size);
			} else if (trade != null) {
				groupbusinfo = GroupBusinessinfoModel.dao.find(
						MEMBERBI_ALL_SQL, size);
			} else {
				groupbusinfo = GroupBusinessinfoModel.dao.find(
						MEMBERBI_ALL_SQL, size);
			}

		}
		List<MemberBusinessinfoEntey> mbusinfolist = null;
		if (groupbusinfo != null) {
			MemberBusinessinfoEntey mbusinfo = null;
			GroupBusinessinfoBrowseModel gbbm = null;
			SystemPointlikeModel spm = null;
			SystemReviewModel srm = null;
			SystemCollectModel scm = null;
			mbusinfolist = new ArrayList<MemberBusinessinfoEntey>();

			for (int i = 0; i < groupbusinfo.size(); i++) {
				mbusinfo = new MemberBusinessinfoEntey();
				mbusinfo.setN0(groupbusinfo.get(i).getStr(
						GroupBusinessinfoModel.ID));
				mbusinfo.setN1(groupbusinfo.get(i).getStr(
						GroupBusinessinfoModel.BIIAMGES));
				mbusinfo.setN2(groupbusinfo.get(i).getStr(
						GroupBusinessinfoModel.BITITLE));
				mbusinfo.setN3(DateUtils.format(
						groupbusinfo.get(i).getDate(
								GroupBusinessinfoModel.CREATETIME),
						"yyyy-MM-dd"));
			//	GroupMemberinfoModel userinfo = GroupMemberinfoModel.dao
						//.findFirst(MEMBERINFOMIDSSQL, groupbusinfo.get(i)
								//.getStr(GroupBusinessinfoModel.MID));
				//通过mid查询会员基础数据
				GroupMemberModel nowUser = GroupMemberModel.dao.
						findFirst(MEMBERMIDSSQL,groupbusinfo.get(i)
								.getStr(GroupBusinessinfoModel.MID));
//				mbusinfo.setN4(userinfo != null ? userinfo
//						.getStr(GroupMemberinfoModel.REALNAME)
//						: Code.FINAL_STRING_MEMBER);
				mbusinfo.setN4(nowUser != null ? nowUser
						.getStr(GroupMemberModel.REALNAME)
						: Code.FINAL_STRING_MEMBER);
				GroupInfoModel groupinfo = GroupInfoModel.dao.findFirst(
						GROUPINFOBYIDSQL,
						groupbusinfo.get(i).getStr(
								GroupBusinessinfoModel.GROUPIDS));
				mbusinfo.setN5(groupinfo != null ? groupinfo
						.getStr(GroupInfoModel.GNAME) : Code.FINAL_STRING_GROUP);
				GroupContactsModel gcontacts = GroupContactsModel.dao
						.findFirst(GROUPCONTACTS_MID_QUERY_SQL, groupbusinfo
								.get(i).getStr(GroupBusinessinfoModel.MID));
				mbusinfo.setN6(gcontacts != null ? gcontacts
						.getStr(GroupContactsModel.CNAMES)
						: Code.FINAL_STRING_CONTE);
				gbbm = GroupBusinessinfoBrowseModel.dao.findFirst(
						GROUPBUSINESSINFOBROWSE_SUMNUMBER_SQL, groupbusinfo
								.get(i).getStr(GroupBusinessinfoModel.ID));
				mbusinfo.setN7(gbbm != null ? gbbm.getNumber(
						GroupBusinessinfoBrowseModel.SCOUNT).intValue() : 0);
				srm = SystemReviewModel.dao.findFirst(GET_REVIEW_SUMNUMBER_SQL,
						groupid, did,
						groupbusinfo.get(i).getStr(GroupBusinessinfoModel.ID));
				mbusinfo.setN8(srm != null ? srm.getNumber(
						SystemReviewModel.SCOUNT).intValue() : 0);
				spm = SystemPointlikeModel.dao.findFirst(
						GET_POINTLIKE_SUMNUMBER_SQL, groupid, did, groupbusinfo
								.get(i).getStr(GroupBusinessinfoModel.ID));
				mbusinfo.setN9(spm != null ? spm.getNumber(
						SystemPointlikeModel.SCOUNT).intValue() : 0);
				spm = SystemPointlikeModel.dao.findFirst(
						GET_POINTLIKE_ISOPEN_SQL, groupid, did, groupbusinfo
								.get(i).getStr(GroupBusinessinfoModel.ID), mid);
				mbusinfo.setN10(spm != null ? 0 : 1);
				scm = SystemCollectModel.dao.findFirst(
						SYSTEMCOLLECT_ISCOLL_SQL, groupid, did, groupbusinfo
								.get(i).getStr(GroupBusinessinfoModel.ID), mid);
				mbusinfo.setN11(scm != null ? 0 : 1);

				mbusinfolist.add(mbusinfo);
			}
		}
		DataResponse response = new DataResponse();
		response.setCode(groupbusinfo != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(groupbusinfo != null ? "SUCCESS" : "无商机列表");
		response.setData(mbusinfolist);
		renderJson(response);

	}

	/**
	 * 获取团体电商项目列表 POST /api/group/getgroupecprodinfolist
	 */
	public void getgroupecprodinfolist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int size = getParaToInt("pagesize", 0);// 分页大小
		int type = getParaToInt("type", 0);// 查询范围
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(size, "pagesize can not be null")
				.put(type, "type can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		List<GroupEcInfoListEntey> listgeil = null;
		List<GroupEcprodtypeinfoModel> ectypelist = null;
		// 操作如下
		if (type == 0) {
			ectypelist = GroupEcprodtypeinfoModel.dao.find(
					GROUPECTYPE_LIST_SQL, groupid, size);
			if(ectypelist.size()==0)
			{
				ectypelist = GroupEcprodtypeinfoModel.dao.find(
						GROUPECTYPE_LIST_SQL, "88888888888888888888888888888888", size);
			}
		} else {
			ectypelist = GroupEcprodtypeinfoModel.dao.find(
					GROUPECTYPE_ALLLIST_SQL, size);
		}
		if (ectypelist != null &&ectypelist.size()>0) {
			listgeil = new ArrayList<GroupEcInfoListEntey>();
			List<GroupEcInfoListObjectEntey> listgelo = null;
			GroupEcInfoListEntey geile = null;
			GroupEcInfoListObjectEntey geilo = null;

			for (GroupEcprodtypeinfoModel getm : ectypelist) {
				geile = new GroupEcInfoListEntey();
				geile.setN0(getm.getStr(GroupEcprodtypeinfoModel.ID));
				geile.setN1(getm.getStr(GroupEcprodtypeinfoModel.ECTYPENAME));
				geile.setN2(getm
						.getStr(GroupEcprodtypeinfoModel.ECTYPEPARENTID));
				geile.setN3(getm.getNumber(GroupEcprodtypeinfoModel.ORDERIDS)
						.intValue());
				listgelo = new ArrayList<GroupEcInfoListObjectEntey>();
				List<GroupEcprodinfoModel> listgecinfo = GroupEcprodinfoModel.dao
						.find(GROUPECINFO_LIST_SQL,
								getm.getStr(GroupEcprodtypeinfoModel.ID), size);
				if (listgecinfo != null) {
					for (GroupEcprodinfoModel ge : listgecinfo) {
						geilo = new GroupEcInfoListObjectEntey();
						geilo.setN0(ge.getStr(GroupEcprodinfoModel.ID));
						geilo.setN1(ge.getStr(GroupEcprodinfoModel.ECPRODNAME));
						geilo.setN2(ge.getStr(GroupEcprodinfoModel.ECPRODDESC));
						geilo.setN3(ge
								.getStr(GroupEcprodinfoModel.ECPRODHOMEIMAGE));

						listgelo.add(geilo);
					}
				}
				geile.setN4(listgelo);
				listgeil.add(geile);
			}
		}
		DataResponse response = new DataResponse();
		response.setCode(ectypelist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(ectypelist != null ? "SUCCESS" : "无产品信息");
		response.setData(listgeil);
		renderJson(response);
	}
	
	public void getgroupecprodListByTypeID()
	{
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID

		String ecptypeid = getPara("ecptypeid");// 产品ID
		int size = getParaToInt("pagesize", 0);// 分页大小
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(ecptypeid, "ecptypeid can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		List<GroupEcInfoListObjectEntey> listgelo = null;
		List<GroupEcprodinfoModel> listgecinfo = GroupEcprodinfoModel.dao
				.find(GROUPECINFO_LIST_SQL,ecptypeid, size);
		if (listgecinfo != null) {
			listgelo = new ArrayList<GroupEcInfoListObjectEntey>();
			GroupEcInfoListObjectEntey geilo = null;
			for (GroupEcprodinfoModel ge : listgecinfo) {
				geilo = new GroupEcInfoListObjectEntey();
				geilo.setN0(ge.getStr(GroupEcprodinfoModel.ID));
				geilo.setN1(ge.getStr(GroupEcprodinfoModel.ECPRODNAME));
				geilo.setN2(ge.getStr(GroupEcprodinfoModel.ECPRODDESC));
				geilo.setN3(ge
						.getStr(GroupEcprodinfoModel.ECPRODHOMEIMAGE));
				listgelo.add(geilo);
			}
		}
		DataResponse response = new DataResponse();
		response.setCode(listgecinfo != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(listgecinfo != null ? "SUCCESS" : "无产品信息");
		response.setData(listgelo);
		renderJson(response);
	}
	/**
	 * 获取团体电商产品详情 POST /api/group/getgroupecprodinfoObject
	 */
	public void getgroupecprodinfoObject() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID

		String ecpid = getPara("ecpid");// 产品ID
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(ecpid, "ecpid can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		GroupEcprodinfoModel gedm = GroupEcprodinfoModel.dao.findById(ecpid);
		GroupEcInfoEntey gecinfo = null;
		if (gedm != null) {
			gecinfo = new GroupEcInfoEntey();
			gecinfo.setN0(gedm.getStr(GroupEcprodinfoModel.ID));
			gecinfo.setN1(gedm.getNumber(GroupEcprodinfoModel.ISOUTLINK)
					.intValue());
			if (gedm.getNumber(GroupEcprodinfoModel.ISOUTLINK).intValue() == 1) {
				gecinfo.setN2(gedm.getStr(GroupEcprodinfoModel.OUTURL));
			} else {
				gecinfo.setN2(gedm.getStr(GroupEcprodinfoModel.ECPRODCOMMENT));
				gecinfo.setN3(gedm.getStr(GroupEcprodinfoModel.ECPRODUNIT));
				gecinfo.setN4(gedm.getDouble(GroupEcprodinfoModel.ECPRODPRICE));
				gecinfo.setN5(gedm.getNumber(
						GroupEcprodinfoModel.ECPRODINVENTORY).intValue());
			}
		}
		DatumResponse response = new DatumResponse();
		response.setCode(gedm != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gedm != null ? "SUCCESS" : "无产品详情");
		response.setDatum(gecinfo);
		renderJson(response);

	}

	/**
	 * 电商项目提交订单 POST /api/group/savegroupecorder
	 */
	public void savegroupecorder() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		
		GroupEcOrder fb=null;
		String groupid=null,mid=null,did=null,ecid=null,mcaid=null,eccomment=null,ecunit=null;
		Integer ecnum=0,ecprice=0;
		try {
			fb = getRepuestJosnObject(getRequest().getReader(), GroupEcOrder.class);// 取出请求接口参数
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (fb != null) {
			groupid=fb.getGroupid();
			mid=fb.getMid();
			did=fb.getDid();
			ecid=fb.getEcid();
			mcaid=fb.getMcaid();
			eccomment=fb.getEccomment();
			ecunit=fb.getEcunit();
			ecnum=fb.getEcnum();
			ecprice=fb.getEcprice();
		}else
			return;
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(ecnum, "ecnum can not be null")
				.put(ecprice, "ecprice can not be null")
				.put(eccomment, "eccomment can not be null")
				.put(mcaid, "mcaid can not be null")
				.put(ecunit, "ecunit can not be null")
				.put(ecid, "ecid can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		String orderid = OrderUtils.getOrderNo();
		// 保存数据
		boolean flag = new GroupEcprodOrderModel()
				.set(GroupEcprodOrderModel.ID, getCreateUUId())
				.set(GroupEcprodOrderModel.VERSION, 0)
				.set(GroupEcprodOrderModel.ORDERIDS, 0)
				.set(GroupEcprodOrderModel.GROUPIDS, groupid)
				.set(GroupEcprodOrderModel.MID, mid)
				.set(GroupEcprodOrderModel.ECPRODID, ecid)
				.set(GroupEcprodOrderModel.MCAID, mcaid)
				.set(GroupEcprodOrderModel.OMESSAGE, eccomment)
				.set(GroupEcprodOrderModel.OSUMPRICE, ecnum * ecprice)
				.set(GroupEcprodOrderModel.OUNIT, ecunit)
				.set(GroupEcprodOrderModel.OID, orderid)
				.set(GroupEcprodOrderModel.CREATETIME, DateUtils.getDate())
				.save();

		// 返回数据
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL,
				flag ? orderid : Code.FINAL_STRING_ERROR));
	}

	/**
	 * 获取会员的收货地址列表 POST /api/group/getmemberaddresslist
	 */
	public void getmemberaddresslist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int size = getParaToInt("pagesize", 0);// 分页大小
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(size, "pagesize can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		List<GroupMemberCaddressModel> gmcmlist = GroupMemberCaddressModel.dao
				.find(MEMBERADDRESS_LIST_SQL, groupid, mid, size);
		List<MemberCAddressEntey> listcad = null;
		if (gmcmlist != null) {
			listcad = new ArrayList<MemberCAddressEntey>();
			MemberCAddressEntey mcae = null;
			for (GroupMemberCaddressModel gmcm : gmcmlist) {
				mcae = new MemberCAddressEntey();
				mcae.setN0(gmcm.getStr(GroupMemberCaddressModel.ID));
				mcae.setN1(gmcm.getNumber(GroupMemberCaddressModel.ISDEFAULT)
						.intValue());
				mcae.setN2(gmcm.getStr(GroupMemberCaddressModel.CNAME));
				mcae.setN3(gmcm.getStr(GroupMemberCaddressModel.CTEL));
				mcae.setN4(gmcm.getStr(GroupMemberCaddressModel.CADDRESS));
				listcad.add(mcae);
			}
		}
		DataResponse response = new DataResponse();
		response.setCode(gmcmlist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gmcmlist != null ? "SUCCESS" : "无收货信息列表");
		response.setData(listcad);
		renderJson(response);
	}

	/**
	 * 新增会员的收货地址信息 POST /api/group/addmemberaddressinfo
	 */
	public void addmemberaddressinfo() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID

		String cname = getPara("cname");// 联系人
		String ctel = getPara("ctel");// 联系电话
		String caddress = getPara("caddress");// 地址
		int isdefault = getParaToInt("isdefault", 0);// 是否默认

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(caddress, "caddress can not be null")
				.put(ctel, "ctel can not be null")
				.put(cname, "cname can not be null")
				.put(isdefault, "isdefault can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}

		// 保存数据
		boolean flag = new GroupMemberCaddressModel()
				.set(GroupMemberCaddressModel.ID, getCreateUUId())
				.set(GroupMemberCaddressModel.VERSION, 0)
				.set(GroupMemberCaddressModel.ORDERIDS, 0)
				.set(GroupMemberCaddressModel.GROUPIDS, groupid)
				.set(GroupMemberCaddressModel.MID, mid)
				.set(GroupMemberCaddressModel.CNAME, cname)
				.set(GroupMemberCaddressModel.CTEL, ctel)
				.set(GroupMemberCaddressModel.CADDRESS, caddress)
				.set(GroupMemberCaddressModel.ISDEFAULT, isdefault)
				.set(GroupMemberCaddressModel.CREATETIME, DateUtils.getDate())
				.save();

		// 返回数据
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL,
				flag ? Code.FINAL_STRING_SUCCESS : Code.FINAL_STRING_ERROR));
	}

	/**
	 * 编辑会员的收货地址信息 POST /api/group/editmemberaddressinfo
	 */
	public void editmemberaddressinfo() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String mcaid = getPara("mcaid");// 收货信息ID

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null")
				.put(mcaid, "mcaid can not be null"))) {
			return;
		}
		boolean flag = false;
		BaseResponse response = new BaseResponse();
		GroupMemberCaddressModel gmcm = GroupMemberCaddressModel.dao
				.findById(mcaid);

		String cname = getPara("cname");
		if (StringUtils.isNotEmpty(cname)) {
			gmcm.set(GroupMemberCaddressModel.CNAME, cname);
			flag = true;
		}

		String ctel = getPara("ctel");
		if (StringUtils.isNotEmpty(ctel)) {
			gmcm.set(GroupMemberCaddressModel.CTEL, ctel);
			flag = true;
		}

		String caddress = getPara("caddress");
		if (StringUtils.isNotEmpty(caddress)) {
			gmcm.set(GroupMemberCaddressModel.CADDRESS, caddress);
			flag = true;
		}

		Integer isdefault = getParaToInt("isdefault", 0);
		if (null != isdefault) {
			gmcm.set(GroupMemberCaddressModel.ISDEFAULT, isdefault);
			flag = true;
		}

		if (flag) {
			boolean update = gmcm.update();
			renderJson(response.setCode(update ? Code.SUCCESS : Code.FAIL)
					.setMessage(
							update ? Code.FINAL_STRING_SUCCESS
									: Code.FINAL_STRING_ERROR));
		} else {
			renderArgumentError("必须修改某一个属性！");
		}
	}

	/**
	 * 获取团体炫列表 POST /api/group/getshowmeinfobygidlist
	 */
	public void getshowmeinfobygidlist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int type = getParaToInt("type", 0);// 类型
		int pagesize = getParaToInt("pagesize", 0);// 分页大小
		int curCount = getParaToInt("curCount", 0);// 当前数量
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(type, "type can not be null")
				.put(did, "did can not be null")
				.put(pagesize, "pagesize can not be null")
				.put(groupid, "groupid can not be null"))) {
			return;
		}
		List<GroupMemberShowtimeModel> gmsmlist = null;
		if (type == 0) {
			gmsmlist = GroupMemberShowtimeModel.dao.find(
					MEMBERSHOWTIME_GROUPID_SQL, groupid, curCount,curCount+pagesize);
		} else
			gmsmlist = GroupMemberShowtimeModel.dao.find(
					MEMBERSHOWTIME_GROUPIDANDMID_SQL, groupid, mid, pagesize);

		List<MemberShowtimeEntey> listste = null;
		if (gmsmlist != null) {
			MemberShowtimeEntey mse = null;
			SystemPointlikeModel spm = null;
			SystemReviewModel srm = null;
			GroupMemberConcernModel gmcm = null;
			GroupMShowBrowseModel gmsbm=null;
			listste = new ArrayList<MemberShowtimeEntey>();
			for (GroupMemberShowtimeModel gmsm : gmsmlist) {
				mse = new MemberShowtimeEntey();
				mse.setN0(gmsm.getStr(GroupMemberShowtimeModel.ID));
				GroupMemberinfoModel minfo = GroupMemberinfoModel.dao
						.findFirst(MEMBERINFOMIDSSQL,
								gmsm.getStr(GroupMemberShowtimeModel.MID));
				//通过mid查询会员基础数据
				GroupMemberModel nowUser = GroupMemberModel.dao.
						findFirst(MEMBERMIDSSQL,gmsm.getStr(GroupMemberShowtimeModel.MID));
//				mse.setN1(minfo != null ? minfo
//						.getStr(GroupMemberinfoModel.HEADIMAGE) : "");
//				mse.setN2(minfo != null ? minfo
//						.getStr(GroupMemberinfoModel.REALNAME) : "");
				mse.setN1(nowUser != null ? nowUser
						.getStr(GroupMemberModel.HEADIMAGE) : "");
				mse.setN2(nowUser != null ? nowUser
						.getStr(GroupMemberModel.REALNAME) : "");
				mse.setN12(minfo != null ? minfo
						.getStr(GroupMemberinfoModel.MID) : "");
				mse.setN3(DateUtils.formatDate(gmsm
						.getDate(GroupMemberShowtimeModel.CREATETIME)));
				mse.setN4(gmsm.getStr(GroupMemberShowtimeModel.SHOWCOMMENT));
				mse.setN5(gmsm.getStr(GroupMemberShowtimeModel.SHOWIMAGEURLS));
				gmcm = GroupMemberConcernModel.dao.findFirst(
						MEMBERCONCERN_SUMNUMBER_SQL, groupid, did,
						gmsm.getStr(GroupMemberShowtimeModel.ID));
				mse.setN6(gmcm != null ? gmcm.getNumber(
						GroupMemberConcernModel.SCOUNT).intValue() * 100 : 0);
				mse.setN11(gmcm != null ? gmcm.getNumber(
						GroupMemberConcernModel.SCOUNT).intValue() : 0);
				spm = SystemPointlikeModel.dao.findFirst(
						GET_POINTLIKE_SUMNUMBER_SQL, groupid, did,
						gmsm.getStr(GroupMemberShowtimeModel.ID));
				mse.setN7(spm != null ? spm.getNumber(
						SystemPointlikeModel.SCOUNT).intValue() : 0);
				spm = SystemPointlikeModel.dao.findFirst(
						GET_POINTLIKE_ISOPEN_SQL, groupid, did,
						gmsm.getStr(GroupMemberShowtimeModel.ID), mid);
				mse.setN8(spm != null ? 0 : 1);
				gmcm = GroupMemberConcernModel.dao.findFirst(
						MEMBERCONCERN_ISCONCERN_SQL, groupid, did,
						gmsm.getStr(GroupMemberShowtimeModel.ID), mid);
				mse.setN9(gmcm != null ? 0 : 1);
				srm = SystemReviewModel.dao.findFirst(GET_REVIEW_SUMNUMBER_SQL,
						groupid, did, gmsm.getStr(GroupMemberShowtimeModel.ID));
				mse.setN10(srm != null ? srm
						.getNumber(SystemReviewModel.SCOUNT).intValue() : 0);
				mse.setN13(null);
				gmsbm=GroupMShowBrowseModel.dao.findFirst(GROUPMSHOWBROWSE_SUMNUMBER_SQL, gmsm.getStr(GroupMemberShowtimeModel.ID));
				
				mse.setN14(gmsbm != null ? gmsbm.getNumber(
						GroupMShowBrowseModel.SCOUNT).intValue() : 0);
				
				listste.add(mse);
			}

		}
		DataResponse response = new DataResponse();
		response.setCode(gmsmlist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gmsmlist != null ? "SUCCESS" : "没有发布炫信息列表");
		response.setData(listste);
		renderJson(response);
	}
	/**
	 * 获取炫操作数据  POST /api/group/getshowmeinfobyAction
	 */
	public void getshowmeinfobyAction()
	{
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String showid = getPara("showid");// 炫ID
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(showid, "type can not be null")
				.put(did, "did can not be null")
				.put(groupid, "groupid can not be null"))) {
			return;
		}
		ShowmeinfoEntey se=null;
		SystemPointlikeModel spm = null;
		SystemReviewModel srm = null;
		GroupMemberConcernModel gmcm = null;
		GroupMemberShowtimeModel gmsm=GroupMemberShowtimeModel.dao.findById(showid);
		if(gmsm!=null)
		{
			se=new ShowmeinfoEntey();
			gmcm = GroupMemberConcernModel.dao.findFirst(
					MEMBERCONCERN_SUMNUMBER_SQL, groupid, did,
					gmsm.getStr(GroupMemberShowtimeModel.ID));
			se.setN0(gmcm != null ? gmcm.getNumber(
					GroupMemberConcernModel.SCOUNT).intValue() * 100 : 0);
			se.setN5(gmcm != null ? gmcm.getNumber(
					GroupMemberConcernModel.SCOUNT).intValue() : 0);
			spm = SystemPointlikeModel.dao.findFirst(
					GET_POINTLIKE_SUMNUMBER_SQL, groupid, did,
					gmsm.getStr(GroupMemberShowtimeModel.ID));
			se.setN1(spm != null ? spm.getNumber(
					SystemPointlikeModel.SCOUNT).intValue() : 0);
			spm = SystemPointlikeModel.dao.findFirst(
					GET_POINTLIKE_ISOPEN_SQL, groupid, did,
					gmsm.getStr(GroupMemberShowtimeModel.ID), mid);
			se.setN2(spm != null ? 0 : 1);
			gmcm = GroupMemberConcernModel.dao.findFirst(
					MEMBERCONCERN_ISCONCERN_SQL, groupid, did,
					gmsm.getStr(GroupMemberShowtimeModel.ID), mid);
			se.setN3(gmcm != null ? 0 : 1);
			srm = SystemReviewModel.dao.findFirst(GET_REVIEW_SUMNUMBER_SQL,
					groupid, did, gmsm.getStr(GroupMemberShowtimeModel.ID));
			se.setN4(srm != null ? srm
					.getNumber(SystemReviewModel.SCOUNT).intValue() : 0);
			List<GroupMShowBrowseModel> browselist = GroupMShowBrowseModel.dao
					.find(GSHOWMEMBERBIBROWSE_ALL_SQL, showid);
			List<SystemCollectEntey> browseobecjtlist = null;
			// GroupMemberinfoModel userinfo=null;
			 GroupMemberModel nowUser = null;//定义会员基础
			if (browselist != null) {
				browseobecjtlist = new ArrayList<SystemCollectEntey>();
				SystemCollectEntey sce = null;
				for (GroupMShowBrowseModel gbb : browselist) {
					sce = new SystemCollectEntey();
					sce.setN0(gbb.getStr(GroupInformBrowse.MID));
				//	userinfo=GroupMemberinfoModel.dao.findFirst(MEMBERINFOMIDSSQL,gbb.getStr(GroupInformBrowse.MID));
					//通过mid查询会员基础数据
					nowUser = GroupMemberModel.dao.findFirst(MEMBERMIDSSQL,
							gbb.getStr(GroupInformBrowse.MID));
//					sce.setN1(userinfo.getStr(GroupMemberinfoModel.HEADIMAGE));
					sce.setN1(nowUser.getStr(GroupMemberModel.HEADIMAGE));
					browseobecjtlist.add(sce);
				}
			}
			se.setN6(browseobecjtlist);
			
		}
		// 记录用户打开通知详情
		new GroupMShowBrowseModel()
				.set(GroupMShowBrowseModel.ID, getCreateUUId())
				.set(GroupMShowBrowseModel.VERSION, 0)
				.set(GroupMShowBrowseModel.ORDERIDS, 0)
				.set(GroupMShowBrowseModel.MID, mid)
				.set(GroupMShowBrowseModel.MSHOWIDS, showid)
				.set(GroupMShowBrowseModel.CREATETIME,
						DateUtils.getDate()).save();
		
		DatumResponse response = new DatumResponse();
		response.setCode(gmsm != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(gmsm != null ? "SUCCESS" : "无炫操作记录");
		response.setDatum(se);
		renderJson(response);
		
	}
	/**
	 * 会员发布炫信息 POST /api/group/sendshowmeinfo
	 */
	public void sendshowmeinfo() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		Showme fb = null;
		String groupid=null,mid=null,did=null,scomment = null,simage = null;// 炫内容
		int stype=0;
		try {
			fb = getRepuestJosnObject(getRequest().getReader(), Showme.class);// 取出请求接口参数
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (fb != null) {
			groupid=fb.getGroupid();
			mid=fb.getMid();
			did=fb.getDid();
			stype=fb.getType();
			scomment = fb.getScomment();
			simage = fb.getSimage();
		}
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(scomment, "scomment can not be null")
				.put(simage, "simage can not be null")
				.put(stype, "stype can not be null")
				.put(groupid, "groupid can not be null"))) {
			return;
		}
		GroupMemberShowtimeModel gbfm = GroupMemberShowtimeModel.dao.findFirst(
				MEMBERSHOWTIME_MAX_ORDERIDS_SQL, groupid);

		boolean flag = new GroupMemberShowtimeModel()
				.set(GroupMemberShowtimeModel.ID, getCreateUUId())
				.set(GroupMemberShowtimeModel.GROUPID, groupid)
				.set(GroupMemberShowtimeModel.MID, mid)
				.set(GroupMemberShowtimeModel.SHOWCOMMENT, scomment)
				.set(GroupMemberShowtimeModel.SHOWIMAGEURLS, simage)
				.set(GroupMemberShowtimeModel.CREATETIME, DateUtils.getDate())
				.set(GroupMemberShowtimeModel.ORDERIDS,
						gbfm != null ? (gbfm.getNumber(
								GroupMemberShowtimeModel.ORDERIDS).intValue() + 1)
								: 1).set(GroupMemberShowtimeModel.VERSION, 0)
				.save();
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL,
				flag ? Code.FINAL_STRING_SUCCESS : Code.FINAL_STRING_ERROR));
	}

	/**
	 * 会员删除自己发布炫信息 POST /api/group/delshowmeinfobymidandsid
	 */
	public void delshowmeinfobymidandsid() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String showid = getPara("showid");// 炫ID
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(showid, "showid can not be null")
				.put(groupid, "groupid can not be null"))) {
			return;
		}

		boolean flag = GroupMemberShowtimeModel.dao.deleteById(showid);
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL,
				flag ? Code.FINAL_STRING_SUCCESS : Code.FINAL_STRING_ERROR));
	}

	/**
	 * 云筑圈 获取前5的信息集合 POST /api/group/gettopfiveinfolist
	 */
	public void gettopfiveinfolist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(groupid, "groupid can not be null"))) {
			return;
		}
		List<GroupInfoModel> gilist = GroupInfoModel.dao
				.find(GROUPINFO_TOP5_SQL);
		List<GroupBusinessinfoModel> gbsilist = GroupBusinessinfoModel.dao
				.find(GROUPBI_TOP5_SQL);
		List<GroupEcprodinfoModel> gecpilist = GroupEcprodinfoModel.dao
				.find(GROUPEC_TOP5_SQL);
		List<YunzoTopFiveInfoEntey> listytfie = new ArrayList<YunzoTopFiveInfoEntey>();
		YunzoTopFiveInfoEntey ytfie = null;
		List<YunzoInfoEntey> infolist = null;
		boolean flag = false;
		if (gilist != null) {
			flag = true;
			ytfie = new YunzoTopFiveInfoEntey();
			ytfie.setN0("11111");
			infolist = new ArrayList<YunzoInfoEntey>();
			YunzoInfoEntey yie = null;
			for (GroupInfoModel gi : gilist) {
				yie = new YunzoInfoEntey();
				yie.setN0(gi.getStr(GroupInfoModel.ID));
				yie.setN1(gi.getStr(GroupInfoModel.GROUPLOGO));
				yie.setN2(gi.getStr(GroupInfoModel.GNAME));
				yie.setN3(gi.getNumber(GroupInfoModel.ORDERIDS).intValue());
				infolist.add(yie);
			}
			ytfie.setN1(infolist);
			listytfie.add(ytfie);
		}
		if (gbsilist != null) {
			flag = true;
			ytfie = new YunzoTopFiveInfoEntey();
			ytfie.setN0("66666");
			infolist = new ArrayList<YunzoInfoEntey>();
			YunzoInfoEntey yie = null;
			for (GroupBusinessinfoModel gi : gbsilist) {
				yie = new YunzoInfoEntey();
				yie.setN0(gi.getStr(GroupBusinessinfoModel.ID));
				yie.setN1(gi.getStr(GroupBusinessinfoModel.BIIAMGES));
				yie.setN2(gi.getStr(GroupBusinessinfoModel.BITITLE));
				yie.setN3(gi.getNumber(GroupBusinessinfoModel.ORDERIDS)
						.intValue());
				infolist.add(yie);
			}
			ytfie.setN1(infolist);
			listytfie.add(ytfie);

		}
		if (gecpilist != null) {
			flag = true;
			ytfie = new YunzoTopFiveInfoEntey();
			ytfie.setN0("77777");
			infolist = new ArrayList<YunzoInfoEntey>();
			YunzoInfoEntey yie = null;
			for (GroupEcprodinfoModel gi : gecpilist) {
				yie = new YunzoInfoEntey();
				yie.setN0(gi.getStr(GroupEcprodinfoModel.ID));
				yie.setN1(gi.getStr(GroupEcprodinfoModel.ECPRODHOMEIMAGE));
				yie.setN2(gi.getStr(GroupEcprodinfoModel.ECPRODNAME));
				yie.setN3(gi.getNumber(GroupEcprodinfoModel.ORDERIDS)
						.intValue());
				infolist.add(yie);
			}
			ytfie.setN1(infolist);
			listytfie.add(ytfie);

		}

		DataResponse response = new DataResponse();
		response.setCode(flag ? Code.SUCCESS : Code.ERROR);
		response.setMessage(flag ? "SUCCESS" : "没有排名信息列表");
		response.setData(listytfie);
		renderJson(response);
	}

	/**
	 * 云筑圈 获取所有团体信息集合 POST /api/group/getallgroupinfolist
	 */
	public void getallgroupinfolist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID

		int size = getParaToInt("pagesize", 0);// 分页大小
		int cut = getParaToInt("curcount", 0);// 分页大小
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(size, "pagesize can not be null")
				.put(groupid, "groupid can not be null"))) {
			return;
		}

		List<GroupInfoModel> grouplist = GroupInfoModel.dao.find(
				GROUPINFO_ALL_SQL, cut,size);
		List<YunzoInfoEntey> listinfo = null;
		if (grouplist != null) {
			listinfo = new ArrayList<YunzoInfoEntey>();
			YunzoInfoEntey yie = null;
			for (GroupInfoModel gim : grouplist) {
				yie = new YunzoInfoEntey();
				yie.setN0(gim.getStr(GroupInfoModel.ID));
				yie.setN1(gim.getStr(GroupInfoModel.GROUPLOGO));
				yie.setN2(gim.getStr(GroupInfoModel.GNAME));
				yie.setN3(gim.getNumber(GroupInfoModel.ORDERIDS).intValue());

				listinfo.add(yie);
			}
		}

		DataResponse response = new DataResponse();
		response.setCode(grouplist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(grouplist != null ? "SUCCESS" : "没有团体信息列表");
		response.setData(listinfo);
		renderJson(response);
	}

	/**
	 * 云筑圈 根据关键字或地域搜索全国团体信息集合 POST /api/group/queryareaandlikeallgroupinfolist
	 */
	@SuppressWarnings("unused")
	public void queryareaandlikeallgroupinfolist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid =null,mid=null,did=null,areaname=null,likename=null;
		int size=0,cut=0;
		GroupInfoEntny fb = null;
		try {
			fb = getRepuestJosnObject(getRequest().getReader(), GroupInfoEntny.class);// 取出请求接口参数
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (fb != null) {
			groupid=fb.getGroupid();
			mid=fb.getMid();
			did=fb.getDid();
			areaname=fb.getAreaname();
			likename=fb.getLikename();
			size=fb.getPagesize();
			cut=fb.getCurcount();
		}else
			return;
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(size, "pagesize can not be null")
				.put(groupid, "groupid can not be null"))) {
			return;
		}
		

		List<GroupInfoModel> grouplist = null;
		if (areaname != null && likename != null) {
			grouplist = GroupInfoModel.dao.find("SELECT * FROM y_group_info WHERE 1=1 AND status=0 AND gisopenstrategy=0  AND  gaddress like '%"+areaname+"%' AND gname LIKE '%"+likename+"%' order by orderids limit "+cut+","+size);
		} else if (areaname != null) {
			grouplist = GroupInfoModel.dao.find("SELECT * FROM y_group_info WHERE 1=1 AND status=0 AND gisopenstrategy=0  AND  gaddress like '%"+areaname+"%'  order by orderids limit "+cut+","+size);
		} else if (likename != null) {
			grouplist = GroupInfoModel.dao.find("SELECT * FROM y_group_info WHERE 1=1 AND status=0 AND gisopenstrategy=0  AND gname LIKE '%"+likename+"%' order by orderids limit "+cut+","+size);
		} else
			grouplist = GroupInfoModel.dao.find(GROUPINFO_ALL_SQL, cut,size);

		List<YunzoInfoEntey> listinfo = null;
		if (grouplist != null) {
			listinfo = new ArrayList<YunzoInfoEntey>();
			YunzoInfoEntey yie = null;
			for (GroupInfoModel gim : grouplist) {
				yie = new YunzoInfoEntey();
				yie.setN0(gim.getStr(GroupInfoModel.ID));
				yie.setN1(gim.getStr(GroupInfoModel.GROUPLOGO));
				yie.setN2(gim.getStr(GroupInfoModel.GNAME));
				yie.setN3(gim.getNumber(GroupInfoModel.ORDERIDS).intValue());
				listinfo.add(yie);
			}
		}

		DataResponse response = new DataResponse();
		response.setCode(grouplist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(grouplist != null ? "SUCCESS" : "没有团体信息列表");
		response.setData(listinfo);
		renderJson(response);
	}

	/**
	 * 云筑圈 获取全国地市信息是否有更新 POST /api/group/getcityinfoisupdate
	 */
	public void getcityinfoisupdate() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		int lvnmb = getParaToInt("localContactCacheVersion", 0);// 缓存最大号
		// 校验参数, 确保不能为空
		if (!notNull(Require.me()
				.put(lvnmb, "localContactCacheVersion can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		BasicDictModel GCM = BasicDictModel.dao.findFirst(
				TRADE_MAX_VERSION_SQL, did);
		// 返回数据
		renderJson(new BaseResponse(Code.SUCCESS, lvnmb == GCM.getNumber(
				BasicDictModel.VERSION).intValue() ? Code.FINAL_STRING_EORR
				: Code.FINAL_STRING_SUSS));
	}

	/**
	 * 云筑圈 获取全国地市信息集合 POST /api/group/getallcityinfolist
	 */
	public void getallcityinfolist() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID

		int size = getParaToInt("pagesize", 0);// 分页大小
		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(mid, "mid can not be null")
				.put(did, "did can not be null")
				.put(size, "pagesize can not be null")
				.put(groupid, "groupid can not be null"))) {
			return;
		}
		List<BasicDictModel> conlist = BasicDictModel.dao.find(TRADE_LIST_SQL,
				did, size);
		List<YunzoCityEntey> listtrade = null;
		if (conlist != null) {
			listtrade = new ArrayList<YunzoCityEntey>();
			YunzoCityEntey ste = null;
			for (BasicDictModel bdm : conlist) {
				ste = new YunzoCityEntey();
				ste.setN0(bdm.getStr(BasicDictModel.ID));
				ste.setN1(bdm.getStr(BasicDictModel.NAMES));
				ste.setN1(bdm.getStr(BasicDictModel.PARENTIDS));
				ste.setN3(bdm.getNumber(BasicDictModel.VERSION).intValue());
				ste.setN4(Integer.valueOf(bdm.getStr(BasicDictModel.NUMBERS)));

				listtrade.add(ste);
			}
		}
		DataResponse response = new DataResponse();
		response.setCode(conlist != null ? Code.SUCCESS : Code.ERROR);
		response.setMessage(conlist != null ? "SUCCESS" : "无城市列表");
		response.setData(listtrade);
		renderJson(response);
	}

	/**
	 * 云筑圈 编辑会员常用城市列表 POST /api/group/savemembercitylabel
	 */
	public void savemembercitylabel() {
		if (!"post".equalsIgnoreCase(getRequest().getMethod())) {
			render404();
			return;
		}
		String groupid = getPara("groupid");// 团体ID
		String mid = getPara("mid");// 会员手机号码
		String did = getPara("did");// 类型ID
		String labelvalue = getPara("labelvalue");// 行业ID

		// 校验参数, 确保不能为空
		if (!notNull(Require.me().put(labelvalue, "labelvalue can not be null")
				.put(mid, "mid can not be null")
				.put(groupid, "groupid can not be null")
				.put(did, "did can not be null"))) {
			return;
		}
		// 保存数据
		boolean flag = new GroupMemberLabelModel()
				.set(GroupMemberLabelModel.ID, getCreateUUId())
				.set(GroupMemberLabelModel.VERSION, 0)
				.set(GroupMemberLabelModel.ORDERIDS, 0)
				.set(GroupMemberLabelModel.GROUPID, groupid)
				.set(GroupMemberLabelModel.MID, mid)
				.set(GroupMemberLabelModel.DICTNAME, did)
				.set(GroupMemberLabelModel.LABELVALUE, labelvalue)
				.set(GroupMemberLabelModel.CREATETIME, DateUtils.getDate())
				.save();

		// 返回数据
		renderJson(new BaseResponse(flag ? Code.SUCCESS : Code.FAIL,
				flag ? Code.FINAL_STRING_SUCCESS : Code.FINAL_STRING_ERROR));

	}
}